在 Azure AKS 上部署 KubeSphere

本文演示在 Azure Kubernetes Service 上部署 KubeSphere 的步骤。

准备 AKS 集群

Azure 可以通过提供自动化部署资源功能从而实现基础设施即代码的能力,常用的工具包括 ARM templatesAzure CLI。在本指南中,我们将使用 Azure CLI 创建安装 KubeSphere 所需的所有资源。

使用 Azure Cloud Shell

由于 Azure 提供了基于 Web 的终端,因此您不必在计算机上安装 Azure CLI。单击 Azure 门户右上角菜单栏上的 Cloud Shell 按钮。

Cloud Shell

选择 Bash Shell。

Bash Shell

创建资源组

Azure 资源组是在其中部署和管理 Azure 资源的逻辑组。以下示例在westus区域中创建一个名为KubeSphereRG的资源组。

  1. az group create --name KubeSphereRG --location westus

创建一个 AKS 集群

使用az aks create命令创建 AKS 集群。以下示例创建一个名为KuberSphereCluster的集群,该集群具有三个节点,需要等待几分钟完成。

  1. az aks create --resource-group KubeSphereRG --name KuberSphereCluster --node-count 3 --enable-addons monitoring --generate-ssh-keys

备注

您可以使用--node-vm-size-s选项来更改 Kubernetes 节点的大小,默认值是 Standard_DS2_v2(2v CPU,7GB 内存)。有关更多选项,请参见 az aks create

连接集群

为了能够使用 kubectl 操作该 Kubernetes 集群,需要执行az aks get-credentials命令,该命令下载 Kubernetes CLI 将要使用到的凭据和配置。

  1. az aks get-credentials --resource-group KubeSphereRG --name KuberSphereCluster

查看节点信息

  1. $ kubectl get nodes
  2. NAME STATUS ROLES AGE VERSION
  3. aks-nodepool1-27194461-vmss000000 Ready agent 77s v1.17.13
  4. aks-nodepool1-27194461-vmss000001 Ready agent 63s v1.17.13
  5. aks-nodepool1-27194461-vmss000002 Ready agent 65s v1.17.13

在门户中检查 Azure 资源

执行完以上所有命令后,您可以看到在 Azure Portal 中创建了 2 个资源组。

Resource groups

查看资源组详情

  1. $ az group show --resource-group KubeSphereRG
  2. {
  3. "id": "/subscriptions/6017690f-c286-4a8f-123e-c53e2f3bc7b5/resourceGroups/KubeSphereRG",
  4. "location": "westus",
  5. "managedBy": null,
  6. "name": "KubeSphereRG",
  7. "properties": {
  8. "provisioningState": "Succeeded"
  9. },
  10. "tags": null,
  11. "type": "Microsoft.Resources/resourceGroups"
  12. }

Azure Kubernetes Services 本身将放置在KubeSphereRG中。

Azure Kubernetes Services

所有其他资源都将放置在MC_KubeSphereRG_KuberSphereCluster_westus中,例如 VM,负载均衡器和虚拟网络。

Azure Kubernetes Services

在 AKS 上部署 KubeSphere

请使用以下命令开始部署 KubeSphere。

  1. kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.3.0/kubesphere-installer.yaml
  2. kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.3.0/cluster-configuration.yaml

可以通过以下命令检查安装日志:

  1. kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f

访问 KubeSphere 控制台

要从公共 IP 地址访问 KubeSphere 控制台,需要将服务类型更改为LoadBalancer

  1. kubectl edit service ks-console -n kubesphere-system

找到以下部分,并将类型更改为LoadBalancer

  1. spec:
  2. clusterIP: 10.0.78.113
  3. externalTrafficPolicy: Cluster
  4. ports:
  5. - name: nginx
  6. nodePort: 30880
  7. port: 80
  8. protocol: TCP
  9. targetPort: 8000
  10. selector:
  11. app: ks-console
  12. tier: frontend
  13. version: v3.0.0
  14. sessionAffinity: None
  15. type: LoadBalancer # Change NodePort to LoadBalancer
  16. status:
  17. loadBalancer: {}

保存 ks-console 服务的配置后,可以使用以下命令获取公共 IP 地址(在下方 EXTERNAL-IP)。

  1. $ kubectl get svc/ks-console -n kubesphere-system
  2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. ks-console LoadBalancer 10.0.181.93 13.86.xxx.xxx 80:30194/TCP 13m 6379/TCP 10m

使用 external-ip 地址用默认帐户和密码(admin/[email protected])访问控制台。

启用可插拔组件(可选)

上面的示例演示了默认的最小安装过程,对于可插拔组件,可以在安装之前或之后启用它们。有关详细信息,请参见启用可插拔组件