標籤:val names -- classname 常用 cas status loopback strong
#1.查詢資訊kubectl get [需要查詢的服務]
node 節點
componentstatuses 簡寫 cs 組件狀態
namespaces 簡寫 ns 名命空間
pod pod資訊 添加 (-o wide )查看運行節點
service 查詢service
deployments --all-namespaces
kind分類查詢
all --all-namespaces
查詢所有
--all-namespaces 所有命名空間
###將資訊輸入為yaml格式
kubectl get pod [pod名] -o yaml
nginx-6f858d4d45-sgwdf 1/1 Running 0 3h
[[email protected] ~]# kubectl get pod nginx-6f858d4d45-sgwdf -o yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: 2018-09-01T10:01:55Z
generateName: nginx-6f858d4d45-
...省略
#2.刪除
1.刪除節點
kubectl delete node node1
2.刪除pod
kubectl delete pod $(pod_name) -n $(namespace-name)
3.刪除services
kubectl delete svc $(svc_name) -n $(namespace-name)
#3.建立
1.建立pod
kubectl create -f create_pod.yaml
2.更新pod
kubectl rolling-update pod_v1 -f pod_v2.yaml
3.復原
kubectl rolling-update pod_v2 --rollback
問題定位
1.查詢對象詳細資料
kubectl describe pod [pod名] -n [所在命名空間]
[[email protected] ~]# kubectl describe pod client -n default
Name: client
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: node1/10.0.0.40
Start Time: Sat, 01 Sep 2018 20:12:08 +0800
Labels: run=client
Annotations: <none>
Status: Failed
IP: 10.244.1.5
..........
2.查詢日誌
kubectl logs -f
[pod名] -n [所在命名空間]
[[email protected] ~]# kubectl logs -f client -n default
/ #
/ # ls
bin etc proc sys usr
dev home root tmp var
/ # cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
3: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1450 qdisc noqueue
link/ether 0a:58:0a:f4:01:05 brd ff:ff:ff:ff:ff:ff
inet 10.244.1.5/24 scope global eth0
valid_lft forever preferred_lft forever
.........省略
3.進入容器運行命令,如果pod有多個容器,可用-c指定容器
kubectl exec [pod名稱] -c [docker鏡像] [執行的命令] -n [命名空間]
[[email protected] ~]# kubectl exec nginx-6f858d4d45-sgwdf -c nginx hostname -n default
nginx-6f858d4d45-sgwdf
kubernetes常用命令