接上一篇 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