新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
給你來一份Kubernetes常用命令備忘錄
給你來一份Kubernetes常用命令備忘錄
作者:不焦躁的程序員 2023-09-27 12:28:08
云計(jì)算
云原生 本文主要整理了Kubernetes常用命令,給朋友們一個(gè)備忘錄。

景泰網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),景泰網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為景泰成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的景泰做網(wǎng)站的公司定做!
本文主要整理了Kubernetes常用命令,給朋友們一個(gè)備忘錄。
查看K8S的幫助命令
kubectl --help
切換被操作的集群
默認(rèn)情況下會(huì)在.kube目錄下的config文件里的證書去操作K8S集群。如果碰到需要切換訪問別的K8S集群的場景,可以使用kubectl --kubeconfig xxxxxx去指定某個(gè)證書文件,比如:
kubectl --kubeconfig (xxxx.json | xxxxconfig) get node
創(chuàng)建資源對(duì)象
kubectl apply -f xxx.yaml
查找資源對(duì)象
# 查到node
kubectl get node
# 查到namespace
kubectl get ns
# 查找service
kubectl get svc -n demo
# 查找部署資源
kubectl get deployment -n demo
# 查找pod
kubectl get pods -n demo
# 查找pod,展示更多信息
kubectl get pods -n demo -o wide
描述資源對(duì)象
describe命令非常重要,當(dāng)你部署資源出現(xiàn)問題時(shí),可以通過這個(gè)命令去查看原因。
# 描述pod
kubectl describe pods webapp -n demo
# 描述node
kubectl describe node k8s-worker-2
# 描述ingress
kubectl describe ingress xxxxxx-ingress -n demo
# 描述service
kubectl describe svc web-service -n demo
伸縮資源
擴(kuò)展副本數(shù)到4:
kubectl scale --replicas=4 deployment/xxxxxx -n demo
重新縮減副本數(shù)到2:
kubectl scale --replicas=2 deployment/xxxxxx -n demo
根據(jù)情況自動(dòng)縮放:
kubectl autoscale deployment xxxxxx --min=1 --max=4 -n demo
kubectl autoscale deployment ehome-cloud-server --min=1 --max=3 -n test1 --cpu-percent=80
獲取水平自動(dòng)縮放器
kubectl get hpa -n test1
刪除水平自動(dòng)縮放器
kubectl delete hpa ehome-cloud-server -n test1
操作label
label是集群內(nèi)部用來查找和篩選的標(biāo)簽,非常重要。
kubectl label node k8s-worker-3 app=backend
kubectl label node k8s-worker-3 app-
kubectl get nodes --show-labels
kubectl get nodes k8s-worker-3 --show-labels
kubectl label pods xxxxxx addlabel=addlabelval -n demo
添加污點(diǎn)
# 添加污點(diǎn)
kubectl taint nodes node01 key=value:effect
# 刪除污點(diǎn)
kubectl taint nodes node01 key[:effect]-
刪除資源
kubectl delete -f xxx.yaml
kubectl delete pod xxx -n demo
查看日志
kubectl logs -f xxxxxx-9d8695998-s9cwk -n demo
kubectl logs xxxxxx-9d8695998-s9cwk -n demo
進(jìn)入容器內(nèi)部
kubectl exec -it webapp -n demo -- /bin/sh查看使用資源的情況
kubectl top pod
kubectl top node 網(wǎng)站名稱:給你來一份Kubernetes常用命令備忘錄
瀏覽路徑:http://fisionsoft.com.cn/article/copjdii.html


咨詢
建站咨詢
