Kubernetes - 日常维护

2023-12-14

Node

如何从另一个环境变量引用一个环境变量?

containers:
- env:
  - name: APPID
    vaue: 12000
  - name: LOG_PATH
    value: /var/log/$(APPID)/logs

节点ROLES

kubectl label node k8s-server-150-9 node-role.kubernetes.io/node-80c256g=

污点

kubectl taint nodes cn-hangzhou.10.111.64.122 node-role.kubernetes.io/master=:NoSchedule

kubectl taint nodes cn-hangzhou.10.111.64.122 node-role.kubernetes.io/master:NoSchedule-

标签

kubectl label node cn-hangzhou.10.111.64.122 test=true
kubectl label node cn-hangzhou.10.111.64.122 test-

将k8s-node1节点设置为不可调度模式

kubectl cordon k8s-node1

将当前运行在k8s-node1节点上的容器驱离

kubectl drain k8s-node1

执行完维护后,将节点重新加入调度

kubectl uncordon k8s-node1

Pod

强制删除

kubectl delete pod test-6cf9c4dc9b-g2fj8 --grace-period=0 --force

Deployment

修改镜像

kubectl set image deployment/review-demo review-demo=library/review-demo:0.0.1

修改pod数量

kubectl scale deployment review-demo --replicas 3

查看部署状态

kubectl rollout status deployment/review-demo

查看详情

kubectl describe deployment/review-demo

中止升级

kubectl rollout pause deployment/review-demo

继续升级

kubectl rollout resume deployment/review-demo

history显示详情

--record

查看部署历史

kubectl rollout history deployments/review-demo

回退至上一个版本

kubectl rollout undo deployment/review-demo

回退至指定版本

kubectl rollout undo deployment/review-demo --to-revision=2

打印API

kubectl get ns -v=9

image.png

创建docker认证

kubectl -n qa5 create secret generic ali-login-registry-qa5 --from-file=.dockerconfigjson=/root/.docker/config.json --type=kubernetes.io/dockerconfigjson

jsonpath

kubectl -n pro get deployments.apps -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.replicas}{"\t"}{.spec.template.spec.containers[].resources.requests.cpu}{"\t"}{.spec.template.spec.containers[].resources.requests.memory}{"\t"}{.spec.template.spec.containers[].resources.limits.cpu}{"\t"}{.spec.template.spec.containers[].resources.limits.memory}{"\t"}{..image}{"\n"}{end}'
jq -r '.[] | "\(.labels.product)|\(.alert)|\(.annotations.summary)|\(.for)|\(.expr)"'
jq -r '.[] | "\(.Name)\t\(.Status)\t\(.AlarmTargets[]|.TopicName)\t\(.MonitorTime.Time)\t\(.AlarmTargets[]|.StartTimeOffset)\t\(.Condition)\t\(.AlarmNoticeIds)"'

标题:Kubernetes - 日常维护
地址:https://blog.njqhome.com:8443/articles/2021/10/11/1633886668827.html