---
# System prepended metadata

title: K8s Command
tags: [K8s]

---

# K8s Command

顯示所有 deployment 和他們的 labels
``` cmd
kubectl get deployment --show-labels
```

取得所有 deployment by 指定的 label
``` cmd
kubectl get deployment -l app=nginx //{label key}={label value}
```

調整 deployment 裡面的 pods 數量
``` cmd
kubectl scale deployment {deployment name} --replicas=5 
kubectl scale deployment -f {deployment file path} --replicas=5 
```

更換當前組態 namespace
``` cmd
kubectl config set-context --current --namespace={namespace name}
```

刪除本機儲存的 context
``` cmd
kubectl config delete-context {context name}
```

刪除本機儲存的 cluster
``` cmd
kubectl config delete-cluster {cluster name}
```

刪除本機儲存的 user
``` cmd
kubectl config unset users.{user name}
```

取得 k8s pod 資源用量
``` cmd
kubectl top pods --all-namespaces --containers=true
```
###### tags: `K8s`










