AKS常见管理

网友投稿 325 2022-10-05

AKS常见管理

Azure Kubernetes 服务 (AKS) 通过将操作开销卸载到 Azure,简化了在 Azure 中部署托管 Kubernetes 群集的过程。 作为一个托管的 Kubernetes 服务,Azure 可以自动处理运行状况监视和维护等关键任务。 由于 Kubernetes 主节点由 Azure 管理,因此你只需要管理和维护代理节点。 因此,AKS 是免费的,你只需支付群集中的代理节点费,不需支付主节点的费用。

可使用以下方式创建 AKS 群集:

​​Azure CLI​​​​Azure 门户​​​​Azure PowerShell​​使用模板驱动的部署选项,例如​​Azure 资源管理器模板​​、​​Bicep​​ 和 Terraform。

当你部署 AKS 群集时,系统会为你部署和配置 Kubernetes 主节点和所有节点。 在部署过程中,可以配置高级网络、Azure Active Directory (Azure AD) 集成、监视和其他功能。

当我们在使用AKS时会涉及到创建, 修改,添加node节点, 配置自定义kubelet参数, 指定node 的系统(Windows, Linux), 接下来将例举一些我们使用AKS的常见任务:

1.获取AKS的管理凭据

az aks get-credentials --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER_NAME -a

2.添加节点

创建一个用户模式的node pool,System模式的主要用于存放系统服务pod, 如 metric-server 等, 业务pod建议单独创建一个用户模式的 node pool

az aks nodepool add \ --resource-group $RESOURCE_GROUP \ --cluster-name $AKS_CLUSTER_NAME \ --name userpool \ --labels dept=IT costcenter=9999 \ --node-vm-size Standard_DS4_v2 \ --node-count 1 \ --node-osdisk-size="500" \ --max-pods=250 \ --mode user #查看创建的node poolaz aks nodepool show -g $RESOURCE_GROUP --cluster-name $AKS_CLUSTER_NAME -n userpool az aks nodepool list -g $RESOURCE_GROUP --cluster-name $AKS_CLUSTER_NAME

3.为node设置污点以防配置错误或未授权的应用程序 Pod 意外终止系统 Pod

#添加taintkubectl taint node aks-nodepool1-24501522-vmss000000 CriticalAddonsOnly=true:NoSchedule#查看kubectl describe node | grep Taints#删除taintkubectl taint node aks-nodepool1-24501522-vmss000000 CriticalAddonsOnly=true:NoSchedule-

4.停止node

#Install the aks-preview extensionaz extension add --name aks-preview# Update the extension to make sure you have the latest version installedaz extension update --name aks-preview#注册 PreviewStartStopAgentPool 预览版功能#注册az feature register --namespace "Microsoft.ContainerService" --name "PreviewStartStopAgentPool"#查看az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/PreviewStartStopAgentPool')].{Name:name,State:properties.state}"#刷新az provider register --namespace Microsoft.ContainerService#查看当前的aks node节点列表az aks nodepool list -g $RESOURCE_GROUP --cluster-name $AKS_CLUSTER_NAME --query="[].{nodePoolName:name,poolMode:mode}" -o tableNodePoolName PoolMode-------------- ----------nodepool1 Systemuserpool User#查看节点状态az aks nodepool show -g $RESOURCE_GROUP --cluster-name $AKS_CLUSTER_NAME -n userpool --query "{State:powerState.code, Size:vmSize}" -o tableState Size------- ---------------Stopped Standard_DS4_v2az aks nodepool list -g $RESOURCE_GROUP --cluster-name $AKS_CLUSTER_NAME --query="[].{nodePoolName:name,poolMode:mode,powerState:powerState.code}" -o tableThe behavior of this command has been altered by the following extension: aks-previewNodePoolName PoolMode PowerState-------------- ---------- ------------nodepool1 System Runninguserpool User Stopped

5.node污点应用测试

#设置节点池排斥, 更新现有节点az aks nodepool update \ --resource-group $RESOURCE_GROUP \ --cluster-name $AKS_CLUSTER_NAME \ --name userpool \ --node-taints sku=gpu:NoSchedule \ --no-wait #查看az aks nodepool show -g $RESOURCE_GROUP --cluster-name $AKS_CLUSTER_NAME -n userpool | grep -A2 Taints#部署应用验证cat nginx-toleration.yamlapiVersion: v1kind: Podmetadata: name: mypodspec: containers: - image: mcr.azk8s.cn/oss/nginx/nginx:1.15.9-alpine name: mypod resources: requests: cpu: 100m memory: 128Mi limits: cpu: 1 memory: 2G tolerations: - key: "sku" operator: "Equal" value: "gpu" effect: "NoSchedule" #创建kubectl apply -f nginx-toleration.yaml#查看kubectl describe pod mypodName: mypodNamespace: defaultPriority: 0Node: aks-userpool-37933471-vmss000001/10.240.0.35Start Time: Tue, 26 Jul 2022 08:08:05 +0000Labels: Annotations: Status: RunningIP: 10.240.0.244IPs: IP: 10.240.0.244Containers: mypod: Container ID: containerd://6aa282b0373a994a0ff4d339106ad10ae850e65dd6992940720cb414ad2a835e Image: mcr.azk8s.cn/oss/nginx/nginx:1.15.9-alpine Image ID: mcr.azk8s.cn/oss/nginx/nginx@sha256:a7f0981cc874f707afa6c847e94029264213f46b993be7acdb8831f021f41f68 Port: Host Port: State: Running Started: Tue, 26 Jul 2022 08:08:07 +0000 Ready: True Restart Count: 0 Limits: cpu: 1 memory: 2G Requests: cpu: 100m memory: 128Mi Environment: Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-fpndg (ro)Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled TrueVolumes: kube-api-access-fpndg: Type: Projected (a volume that contains injected data from multiple sources) TokenExpirationSeconds: 3607 ConfigMapName: kube-root-ca.crt ConfigMapOptional: DownwardAPI: trueQoS Class: BurstableNode-Selectors: Tolerations: node.kubernetes.io/memory-pressure:NoSchedule op=Exists node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s sku=gpu:NoScheduleEvents: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 17s default-scheduler Successfully assigned default/mypod to aks-userpool-37933471-vmss000001 Normal Pulling 17s kubelet Pulling image "mcr.azk8s.cn/oss/nginx/nginx:1.15.9-alpine" Normal Pulled 16s kubelet Successfully pulled image "mcr.azk8s.cn/oss/nginx/nginx:1.15.9-alpine" in 1.22128134s Normal Created 15s kubelet Created container mypod Normal Started 15s kubelet Started container mypod

Node Debug

#Node Debugkubectl debug node/aks-userpool-37933471-vmss000001 -it --image=mcr.azk8s.cn/aks/fundamental/base-ubuntu:v0.0.11

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:菜鸟 CPaaS 平台微服务治理实践
下一篇:SpringBoot中的HATEOAS详情
相关文章

 发表评论

暂时没有评论,来抢沙发吧~