k8s一些重要命令
阿新 • • 發佈:2020-10-09
1. 使用k8s在default下臨時啟一個容器(實際上是啟了一個pod,退出後pod自動刪除)
# kubectl run -i --tty --image busybox:1.28.4 dns-test --restart=Never --rm /bin/sh
2. 檢視某個pod的所有labels
# kubectl get pod ng-7965f66cf5-42nnd --show-labels -n dj
3. 獲取 k8s-app=nginx的pod
# kubectl get pod -n dj -l k8s-app=nginx
4. 強制刪除pod(適用於刪除pod時,一直處於terminating狀態)
# kubectl delete pod PODNAME --force --grace-period=0
關於k8s汙點
設定taint
語法:
kubectl taint node [node] key=value[effect]
其中[effect] 可取值: [ NoSchedule | PreferNoSchedule | NoExecute ]
NoSchedule: 一定不能被排程
PreferNoSchedule: 儘量不要排程
NoExecute: 不僅不會排程, 還會驅逐Node上已有的Pod
示例:
kubectl taint node node1 key1=value1:NoSchedule kubectl taint node node1 key1=value1:NoExecute kubectl taint node node1 key2=value2:NoSchedule
檢視taint
kubectl describe node node1
刪除taint
kubectl taint node node1 key1:NoSchedule- # 這裡的key可以不用指定value
kubectl taint node node1 key1:NoExecute-
# kubectl taint node node1 key1- 刪除指定key所有的effect
kubectl taint node node1 key2:NoSchedule-
master節點設定taint
kubectl taint nodes master1 node-role.kubernetes.io/master=:NoSchedule
注意⚠️ : 為master設定的這個taint中, node-role.kubernetes.io/master為key, value為空, effect為NoSchedule
如果輸入命令時, 你丟掉了=符號, 寫成了node-role.kubernetes.io/master:NoSchedule, 會報error: at least one taint update is required錯誤
容忍tolerations主節點的taints
以上面為 master1 設定的 taints 為例, 你需要為你的 yaml 檔案中新增如下配置, 才能容忍 master 節點的汙點
在 pod 的 spec 中設定 tolerations 欄位
tolerations:
- key: "node-role.kubernetes.io/master"
operator: "Equal"
value: ""
effect: "NoSchedule"