kubectl常用命令:
1、 kubectl get po -o wide
kubectl get pods -o wide -n=appserver(帶命名空間)
獲取pods
2、 kubectl get svc
獲取service
3、 kubectl get no
獲取nodes
4、 kubectl get ep
獲取service負載pod ip
5、 kubectl delete pods [pod]
kubectl delete service [service]
刪除單個pod/service
6、 kubectl logs [pods]
查看pod日志
7、 kubectl exec -it [pod] bash
進入pod
8、kubectl describe pods [pod]
查看pod的詳情
9、kubectl get cs
查看k8s各組件狀態(tài)
10、kubectl label nodes kube-node node=ttscarweb kubectl get node -a -l "node=ttscarweb"
master重啟命令
systemctl restart etcd kube-apiserver kube-scheduler kube-controller-manager
slave重啟命令
systemctl restart flanneld kubelet kube-proxy docker
yaml文件
主要是用于定義pods、service等的配置文件
命令:
kubectl create -f *.yaml
kubectl delete -f *.yaml
kubectl apply -f *.yaml
創(chuàng)建/刪除/更新 用yaml定義的各種資源
docker常用命令
1、docker run -itd -v /etc/localtime:/etc/localtime:ro -p 8080:8080 [dockerimages] bash
運行一個docker (開放端口8080)
2、docker exec -it [dockercontainer] bash
進入指定的docker
kubernetes中,如果docker鏡像需要登錄,則需創(chuàng)建secret,創(chuàng)建見
kubectl create secret docker-registry dockerlogin --namespace=appserver --docker-server=*** --docker-username=*** --docker-password=*** --docker-email=***
執(zhí)行docker命令
docker exec -d export /bin/sh /start/start.sh
重要命令
- 刪除版本為null的鏡像
docker images|grep none|awk '{print $3 }'|xargs docker rmi - flanneld錯誤日志
flanneld -alsologtostderr
systemctl status flanneld
route -n
tcpdump -i flannel0 -nn host 172.17.62.0(docker0)
iptables -t nat -L KUBE-SERVICES -n - etcdctl get /atomic.io/network/subnets/172.17.23.0-24
- ifconfig flannel.1 down
- docker rm -f
docker ps -a -q(刪除所有docker);docker rmi -fdocker images -a -q(刪除所有鏡像) - etcdctl get /atomic.io/network/config
- traceroute
注意
- node節(jié)點是可以拼通其他節(jié)點容器ip的!
- http://192.168.24.52:2379/v2/keys
- etcdctl -C http://10.253.44.231:2379 set /atomic.io/network/config '{"Network":"172.17.0.0/16","Backend":{"Type":"vxlan"} }'
etcdctl -C http://10.253.44.231:2379 set /atomic.io/network/config '{"Network":"172.17.0.0/16","SubnetLen":25,"Backend":{"Type":"vxlan"} }' --加上vxlan模式,
etcdctl -C http://10.250.250.7:2379 set /atomic.io/network/config '{"Network":"172.17.0.0/16","SubnetLen":25,"Backend":{"Type":"host-gw"} }'--加上host-gw模式,默認是udp模式,另還有hostgw模式,好像比vxlan還要好,另calico和weave可以替代flannel,比flannel穩(wěn)定。 - 修改host-gw網(wǎng)絡(luò)和vxlan的區(qū)別,就是把type改成相應(yīng)值就行了,其他不用另外配
- vim /etc/sysconfig/flanneld
FLANNEL_OPTIONS="-iface=eth0 -public-ip=10.139.52.91 -ip-masq=true"
(非常重要,如果金融云不指定的話,掛載網(wǎng)卡就是公網(wǎng)網(wǎng)卡了。應(yīng)該用內(nèi)網(wǎng)。這個配置加上后,用vxlan就沒什么問題了,這個問題花費了一個周末) - 如果flannel網(wǎng)絡(luò)不通,重點檢查service docker status和service flannel status,不能有錯誤。
- registry.access.redhat.com/rhel7/pod-infrastructure 這個鏡像不能刪除,是k8s需要的。如果不小心刪除了,需要把這個鏡像從其他node上push到阿里云上,然后pull下來,改/etc/kubernetes/kubelet 的KUBELET_POD_INFRA_CONTAINER值就行了 【這個問題其實是docker版本問題導(dǎo)致的,新版本會有問題,應(yīng)該沿用老版本】
- 除了service的cluster-ip外,其他172.17網(wǎng)段的ip在node上都是能ping通的
- VxLan使用8472端口,8285端口作為UDP
- /run/flannel/subnet.env 是flannel寫的環(huán)境變量; source /run/flannel/subnet.env
- 重啟flannel或其他原因?qū)е耭lannel和docker不在同一個網(wǎng)段的,需要reboot才能解決問題
- vim /etc/docker/daemon.json 設(shè)置"bip":"172.17.10.1/24"可以自定義docker網(wǎng)段
問題解決:
- 要初始化k8s,最好etcd儲存文件也刪掉
- docker保留客戶端ip,service.spec.externalTrafficPolicy: Cluster(默認)和"Local",local值可能導(dǎo)致負載不平衡
參考:
- https://www.kubernetes.org.cn/3682.html(flannel介紹的最詳細的文章)
- http://www.mamicode.com/info-detail-2121290.html、 http://dockone.io/question/1393(flannel網(wǎng)絡(luò)不通定位排查)
- https://blog.csdn.net/ganpuzhong42/article/details/77853131(flannel和其他組件性能對比)
- https://segmentfault.com/a/1190000006594822、 http://www.dockone.io/article/1115(比較好的解決docker網(wǎng)絡(luò)比較文章)