背景
接上一篇 再提一提 Azure CNI,它是由 Azure 团队针基于 CNI 实现的容器网络技术,利用 Azure SDN 的能力,使得容器网络可以连接 Azure VNET。因此使用 Azure CNI 可以:
- Kubernetes 的容器网络和 Azure VNet 在一个平面之上,不需要有 Overlay。
- 同一 Azure VNet 下的虚机也可以直接与 Kubernetes 容器互通,不需要经过负载经衡器。这个可以解决我们在微服务场景下, K8S 里的容器要与 此K8S 集群之外的服务实例之间的通讯,例如我们有 dubbo 或 spring cloud 混合部署的场景。
- 在网络传输效率和资源消耗上会比自己在 Azure 上搭一套使用 Flannel 的 Kubernetes 要好,按照笔者的测试能提升 20%~30%。
对于 acs-engine 除了能支持原生 Kubernetes 具备的特性,更多特性可以参考 [6] , 当然能也能支持 GPU 的机器
前提
- 安装 Azure CLI
- 安装 acs-engine
- 一个可用的 Azure 中国区的账号
步骤
- 通过 Azure CLI 登录 Azure 中国,并且生成一个 Contributor 的操作身份给后续部署 K8S 时建立相关资源使用
az cloud set --name AzureChinaCloud az login az account set --subscription="${SUBSCRIPTION_ID}" #下一行命令会生成一个 service principal, 需要记录 appId 以及 password 留做后续使用 az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}"- 准备 acs-engine 的集群部署描述文件, 由于 json 文件不包含注释的语法,为了能更好的理解下面的某些字段信息,我还是用 # 作为注释符用于解释。当实际操作时请删除相关 # 行目。
{ "apiVersion": "vlabs", # 部署区域 "location": "chinanorth2", "properties": { "orchestratorProfile": { #指定编排引擎类型为 kubernetes "orchestratorType": "Kubernetes", # 指定版本 "orchestratorRelease": "1.11", "kubernetesConfig": { # 该 kubernetes 集群将激活 rbac "enableRbac": true, # 该 kubernetes 集群将使用 Azure CNI 作为容器网络实现 "networkPolicy": "azure" } }, #指定 master 节点信息 "masterProfile": { # 此处为 1 个 master 节点,也可以声明为 3, 或者其奇数 "count": 1, # 给定一个 DNS 前缀,用于声明此 K8S 服务在 azure 中国北二区的子域名。例如此处为: burn-k8s-11.chinanorth2.cloudapp.chinacloudapi.cn "dnsPrefix": "burn-k8s-11", # master 节点的型号 "vmSize": "Standard_D3_v2" }, # 指定 Node 节点列表,可以声明多个, 不同机型分别是多少台,分别用什么操作系统。包括使用可用性集来做高可用性保证,也能使用虚机扩展集 "agentPoolProfiles": [ { "name": "windowspool2", "count": 3, "vmSize": "Standard_D3_v2", "availabilityProfile": "AvailabilitySet", "osType": "Windows" } ], # 在 Windows Kubernetes 的环境里需要 master 仍为 Linux, 在 masterProfile 中未声明使用什么 OS, 默认是 Linux "linuxProfile": { #虚机登录用户名 "adminUsername": "zhaw", "ssh": { "publicKeys": [ { # 虚机登录使用的公钥 "keyData": "ssh-rsa XXX" } ] } }, # node 节点使用的 windows 登陆信息 "windowsProfile": { "adminUsername": "azureuser", "adminPassword": "XXX", "windowsPublisher": "MicrosoftWindowsServer", "windowsOffer": "WindowsServerSemiAnnual", "windowsSku": "Datacenter-Core-1803-with-Containers-smalldisk" }, "servicePrincipalProfile": { #前面生成 service principal 的 appID "clientId": "XXX", #前面生成 service principal 的 password "secret": "XXX" } } }- 使用 acs-engine 根据上述描述文件生成 ARM 的部署文件
# 下面的命令将生成文件目录: _output/<dns_prefix> acs-engine generate kubernetes.json- 在 output/<dnsprefix>/kubeconfig 目录下会生成连接到此 k8s 的 kubeconfig 文件,我们只需要在本地安装
kubectl就可以操作此集群,不需要连到 Master 节点上操作 - 通过 azure CLI 创建一个资源管理库并在其中部署出 k8s
