## 創建 k8s 登入帳號 1. 創建登入帳號 ```yaml= kubectl create serviceaccount azure-pipelines-deploy ``` 2. 創建包含令牌憑據的 Kubernetes Secret ```yaml= kubectl create secret generic azure-pipelines-deploy-token --type=kubernetes.io/service-account-token --dry-run=client -o yaml \ | kubectl annotate --local -o yaml -f - kubernetes.io/service-account.name=azure-pipelines-deploy \ | kubectl apply -f - ``` 3. 通過創建集群角色绑定將 cluster-admin 角色分配给服務帳號 ```yaml= kubectl create clusterrolebinding azure-pipelines-deploy --clusterrole=cluster-admin --serviceaccount=default:azure-pipelines-deploy ``` 4. 取得外部 ip ![](https://hackmd.io/_uploads/H1xC4xNP3.png) 5. 取得 token ```yaml= kubectl get secret azure-pipelines-deploy-token -o yaml > azure-pipelines-deploy-token.yaml ``` ## 創建 azure 連線 1. 在 {porject}/Settings/Service connections 內點選 New service connection ![](https://hackmd.io/_uploads/r1kG8x4Ph.png) 2. 選擇 Kubernetes,點選 Next ![](https://hackmd.io/_uploads/S16HLeVD2.png) 3. 輸入 Kubernetse 參數 1. Authentication method 選擇 service Account 2. Server Url 輸入 Kubernetes Cluster ip 3. Secret 輸入 Kubernetes 創建的使用者 token 4. Service connection name 輸入顯示的連線名稱 5. 點選 save ![](https://hackmd.io/_uploads/S1xiIl4Pn.png) ## 參考資料 [google](https://cloud.google.com/dotnet/docs/creating-cicd-pipeline-vsts-kubernetes-engine?hl=zh-cn#deploying_continuously)