接上一篇 Windows 应用容器 后,想要快速且便利的部署与管理它们,能够借助容器编排工具。对于 Windows 容器,在今天 Service Fabric 会是个更为成熟的选择,在业界有更多的实践案例。笔者将来可能会写几篇关于如何使用 Service Fabric 来实现 Windows 平台下的微服务实践。这次咱们接着上篇的内容往下去快速搭建 Windows Kubernetes 环境。html
Azure 团队为容器编排引擎提供了一个开源的部署工具 acs-engine , 它能够支持在 Azure 上快速部署 Swarm、DC\OS、 Kubernetes 集群,同时具有扩缩 Worker 节点、升级等等。这套工具的大致思路是,利用 Azure Infrastructure 服务的可描述性,声明计算 、存储、网络等服务,同时实现 Kubernetes 与 Azure 整合,从而达到利用一个工具快速部署管理 Kubernetes。和咱们使用 Terraform 相似,只是 acs-engine 是一个和 Azure 集成更为紧密的一个工具,使得这个 Kubernetes 能够利用 Azure CNI 、LoadBalancer 以及云磁盘存储以及云文件存储。下图来源于 ACS-engine 官方说明:再提一提 Azure CNI,它是由 Azure 团队针基于 CNI 实现的容器网络技术,利用 Azure SDN 的能力,使得容器网络能够链接 Azure VNET。所以使用 Azure CNI 能够:node
对于 acs-engine 除了能支持原生 Kubernetes 具有的特性,更多特性能够参考 [6] , 固然能也能支持 GPU 的机器linux
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}"
{ "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" } } }
# 下面的命令将生成文件目录: _output/<dns_prefix> acs-engine generate kubernetes.json
kubectl
就能够操做此集群,不须要连到 Master 节点上操做# 进入到生成的文件目录 cd _output/<dns_prefix> # 建立资源管理库 az group create --name <GROUP_NAME> --location chinanorth2 # 部署 k8s az group deployment create -g <GROUP_NAME> --template-file azuredeploy.json --parameters azuredeploy.parameters.json --verbose
$ kubectl --kubeconfig=kubeconfig.chinanorth2.json get node --show-labels NAME STATUS ROLES AGE VERSION LABELS 35598k8s9000 Ready <none> 1h v1.11.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_D3_v2,beta.kubernetes.io/os=windows,failure-domain.beta.kubernetes.io/region=chinanorth2,failure-domain.beta.kubernetes.io/zone=0,kubernetes.io/hostname=35598k8s9000 35598k8s9001 Ready <none> 1h v1.11.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_D3_v2,beta.kubernetes.io/os=windows,failure-domain.beta.kubernetes.io/region=chinanorth2,failure-domain.beta.kubernetes.io/zone=0,kubernetes.io/hostname=35598k8s9001 35598k8s9002 Ready <none> 1h v1.11.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_D3_v2,beta.kubernetes.io/os=windows,failure-domain.beta.kubernetes.io/region=chinanorth2,failure-domain.beta.kubernetes.io/zone=1,kubernetes.io/hostname=35598k8s9002 k8s-master-35598902-0 Ready master 1h v1.11.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_D3_v2,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=chinanorth2,failure-domain.beta.kubernetes.io/zone=0,kubernetes.azure.com/cluster=wink8s,kubernetes.io/hostname=k8s-master-35598902-0,kubernetes.io/role=master
beta.kubernetes.io/os=windows
,咱们能够经过 yaml 文件中使用 nodeSelector
来指定节点信息apiVersion: v1 kind: Service metadata: name: stdlogclientwin labels: app: stdlogclientwin spec: ports: - port: 80 name: http selector: app: stdlogclientwin type: LoadBalancer --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: stdlogclientwin spec: replicas: 1 template: metadata: labels: app: stdlogclientwin version: v1 spec: containers: - name: stdlogclientwin image: burning1docker/stdlogclientwin:1803 imagePullPolicy: IfNotPresent ports: - containerPort: 80 volumeMounts: - name: hostsdir mountPath: "C:/Windows/System32/drivers/etc" nodeSelector: beta.kubernetes.io/os: windows initContainers: - name: init image: microsoft/windowsservercore:1803 command: - powershell - "Add-Content" - "-Path" - "C:/Windows/System32/drivers/etc/hosts" - "-Value" - "\"127.0.0.1 foo.local\"" volumeMounts: - name: hostsdir mountPath: "C:/Windows/System32/drivers/etc" volumes: - name: hostsdir emptyDir: {}
pod anti-affinity
来把同一容器应用 Pod 平均部署到不一样容错域,以防 Azure 物理故障时致使容器在某一时刻不可用,可参考以下示例:apiVersion: extensions/v1beta1 kind: Deployment metadata: name: cpuloadv1 spec: replicas: 3 template: metadata: labels: app: cpuload version: v1 spec: affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 podAffinityTerm: labelSelector: matchExpressions: - key: app operator: In values: - cpuload topologyKey: failure-domain.beta.kubernetes.io/zone containers: - name: cpuload image: burning1docker/cpuload:V1 imagePullPolicy: IfNotPresent ports: - containerPort: 8080 resources: limits: cpu: "1" requests: cpu: 500m
下一篇: 解决 Prometheus 不能获取 Kubernetes 集群上 Windows 节点的 Metricsgit
Ref:github