[AKS] Azure Kubernetes Service 與常用指令

K8S 服務在業界已經是很常用的一個叢集管理技術了,在這邊記錄一些 K8S 的常用指令與利用 Azure Kubernetes 服務實作的一些輸出,關於 Kubernetes 的介紹可以參考以下的 Youtube 影片,讀文件很累的時候可以聽聽 IBM 的工程師是怎麼介紹 K8S。

本篇我們實作的 K8S 是使用 Azure 提供的 AKS (Azure Kubernetes Services) 來實作,首先我們利用 Azure Portal 裡面新增資源的方法新增一個 K8S 的 Cluster,下圖所示是一個 K8S 資源在 Azure 平台上的控制面板。

一些簡單的指令幫助了解目前 Kubernetes Cluster 的狀態

# 列出所有命名空間中的所有部署 –all-namespaces
bash-5.1$ kubectl get deployments --all-namespaces=true
NAMESPACE     NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   coredns              2/2     2            2           5m1s
kube-system   coredns-autoscaler   1/1     1            1           5m1s
kube-system   metrics-server       1/1     1            1           5m1s
kube-system   omsagent-rs          1/1     1            1           5m1s
kube-system   tunnelfront          1/1     1            1           5m
# 列出特定命名空間中的所有部署 –namespace specific_namespace
bash-5.1$ kubectl get deployments --namespace kube-system
NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
coredns              2/2     2            2           9m32s
coredns-autoscaler   1/1     1            1           9m32s
metrics-server       1/1     1            1           9m32s
omsagent-rs          1/1     1            1           9m32s
tunnelfront          1/1     1            1           9m31s
# 列出目前 Kubernetes Cluster 裡面的所有節點 Nodes
bash-5.1$ kubectl get nodes -o wide
NAME                                STATUS   ROLES   AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
aks-agentpool-34641055-vmss000000   Ready    agent   8m54s   v1.20.7   10.240.0.4    <none>        Ubuntu 18.04.5 LTS   5.4.0-1055-azure   containerd://1.4.8+azure
aks-agentpool-34641055-vmss000001   Ready    agent   8m41s   v1.20.7   10.240.0.5    <none>        Ubuntu 18.04.5 LTS   5.4.0-1055-azure   containerd://1.4.8+azure
# 列出目前 Kubernetes Cluster 裡面的所有 Pods

使用 get pods -o wide 可以看到目前所有 Pods 的情況,如下所示目前 spark-test2 Pod 正在開啟。

bash-5.1$ kubectl get pods -o wide
NAME          READY   STATUS              RESTARTS   AGE   IP           NODE                                NOMINATED NODE   READINESS GATES
spark-test1   2/2     Running             0          25d   10.244.3.3   aks-agentpool-34244082-vmss000000   <none>           <none>
spark-test2   0/2     ContainerCreating   0          98s   <none>       aks-agentpool-34244082-vmss00000b   <none>           <none>

 

一個 K8S 的叢集可以部署多少個 Pods ? 參考連結

檸檬爸在開始接觸 K8S 主要是想要建立一個 On-Demand 的執行平台,所以需要先了解一下一個 K8S 的叢集他的容量可以到多大?查到以下的 K8S 官網訊息,所以一個 K8S 最多可以運行 5000 個節點,每一個節點最多 110 pods,因此不能超過 150000 pods,另外有一個獨立的限制就是不能超過 300000 containers。

A cluster is a set of nodes (physical or virtual machines) running Kubernetes agents, managed by the control plane. Kubernetes v1.22 supports clusters with up to 5000 nodes. More specifically, Kubernetes is designed to accommodate configurations that meet all of the following criteria:

  • No more than 110 pods per node
  • No more than 5000 nodes
  • No more than 150000 total pods
  • No more than 300000 total containers

You can scale your cluster by adding or removing nodes. The way you do this depends on how your cluster is deployed.