一、kubeconfig配置文件
二、kubectl管理命令概要
三、尋找“Failed to pull image”或“ImagePullBackOff”事件。這些會(huì)表明拉取Docker鏡像有問(wèn)題。使用describe排查故障:
四、問(wèn)題排查參考:
一、kubeconfig配置文件
kubectl使用kubeconfig認(rèn)證連接k8s集群,使用kubectl?config指令生成kubeconfig文件。
# cat .kube/config

在其它節(jié)點(diǎn)使用kubectl命令配置:

如果在集群之外的機(jī)器安裝,需要先安裝kubectl,讓后再重復(fù)上面的命令即可。

# cat /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg


二、kubectl管理命令概要
參考地址:https://kubernetes.io/zh-cn/docs/reference/kubectl/
# kubectl --help


kubectl命令補(bǔ)全安裝:
# yum install bash-completion -y
# source /usr/share/bash-completion/bash_completion
# source <(kubectl completion bash)

查看service與pod的對(duì)應(yīng)關(guān)系:

導(dǎo)出yaml文件:
# kubectl get pods calico-node-h5s28 -o yaml -n kube-system > calico.yaml
查看所有標(biāo)簽:
# kubectl get pods --show-labels -n kube-system
過(guò)濾標(biāo)簽:
# kubectl get pods --show-labels -l component=etcd,tier=control-plane -n kube-system

注:service的selector標(biāo)簽選擇器字段與pod標(biāo)簽確定匹配關(guān)系
查看指定容器分布節(jié)點(diǎn):
# kubectl describe pods dev-market-gateway-6c6f8c5bfd-kkgp4
查看所有容器分布節(jié)點(diǎn):

刪除pod:
# kubectl delete pod dev-market-gateway-6c6f8c5bfd-zxjct

擴(kuò)充副本數(shù):
# kubectl get deployment -n default

#?kubectl scale deployment dev-market-administration-intelligent-oilgas-system --replicas=1
查看pod運(yùn)行信息:
# kubectl get pod -o wide --no-headers

# kubectl describe pods dev-market-administration-intelligent-oilgas-system-84ccbcnv4ss
查看日志:
# kubectl logs -f dev-market-administration-intelligent-oilgas-system-84ccbcnv4ss
登錄特定容器:
# kubectl exec -it dev-market-administration-intelligent-oilgas-system-84ccbcnv4ss /bin/bash
# kubectl exec -it dev-market-coupon-5b9d867b86-khblw -- bash

刪除pod:
# kubectl delete -f market-merchant_intelligent_oilgas_system.yaml
刪除特定容器:
# kubectl delete pod/dev-market-merchant-intelligent-oilgas-5cfc9d9786-cvwjr
查看應(yīng)用對(duì)應(yīng)的IP和端口/查看service后端關(guān)聯(lián)的一組pods:
# kubectl get ep
# kubectl get endpoints

三、尋找“Failed to pull image”或“ImagePullBackOff”事件。這些會(huì)表明拉取Docker鏡像有問(wèn)題。使用describe排查故障:


四、問(wèn)題排查參考:
https://zhuanlan.zhihu.com/p/639994067
五、k8s不進(jìn)入容器執(zhí)行命令
# kubectl exec -n jiaoda seb-algorithms-784595c99f-j428k -- ls /opt
