基础命令
1. 查看节点信息
# 添加-o wide参数可以输出更详细的信息
kubectl get no -o wide
[root@k8s-master ~]# kubectl get no -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 66d v1.23.6 192.168.228.140 <none> CentOS Linux 7 (Core) 3.10.0-1160.114.2.el7.x86_64 docker://20.10.0
k8s-node-1 Ready <none> 24d v1.23.6 192.168.228.141 <none> CentOS Linux 7 (Core) 3.10.0-1160.114.2.el7.x86_64 docker://20.10.0
k8s-node-2 Ready <none> 24d v1.23.6 192.168.228.142 <none> CentOS Linux 7 (Core) 3.10.0-1160.114.2.el7.x86_64 docker://20.10.0
[root@k8s-master ~]#
2. 查看命名空间
# 添加-o wide参数可以输出更详细的信息
[root@k8s-master ~]# kubectl get ns -o wide
NAME STATUS AGE
default Active 66d
kube-node-lease Active 66d
kube-public Active 66d
kube-system Active 66d
[root@k8s-master ~]#
3. 查看pod信息
# 添加-o wide参数可以输出更详细的信息
[root@k8s-master ~]# kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-85b98978db-r7krm 0/1 ImagePullBackOff 1 (19m ago) 23d 10.244.109.77 k8s-node-1 <none> <none>
[root@k8s-master ~]#
# 查看指定命名空间下的pod详细信息
[root@k8s-master ~]# kubectl get po -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
calico-kube-controllers-64cc74d646-jksnt 1/1 Running 3 (34m ago) 24d 10.244.109.78 k8s-node-1 <none> <none>
calico-node-9gjl5 1/1 Running 3 (34m ago) 24d 192.168.228.140 k8s-master <none> <none>
calico-node-nlscs 1/1 Running 3 (34m ago) 24d 192.168.228.142 k8s-node-2 <none> <none>
calico-node-q9qr6 1/1 Running 3 (34m ago) 24d 192.168.228.141 k8s-node-1 <none> <none>
coredns-6d8c4cb4d-ptxdg 1/1 Running 3 (34m ago) 66d 10.244.109.79 k8s-node-1 <none> <none>
coredns-6d8c4cb4d-rmh24 1/1 Running 3 (34m ago) 66d 10.244.109.76 k8s-node-1 <none> <none>
etcd-k8s-master 1/1 Running 6 (34m ago) 66d 192.168.228.140 k8s-master <none> <none>
kube-apiserver-k8s-master 1/1 Running 6 (34m ago) 66d 192.168.228.140 k8s-master <none> <none>
kube-controller-manager-k8s-master 1/1 Running 6 (34m ago) 66d 192.168.228.140 k8s-master <none> <none>
kube-proxy-2rvch 1/1 Running 3 (34m ago) 24d 192.168.228.142 k8s-node-2 <none> <none>
kube-proxy-bfx88 1/1 Running 5 (34m ago) 66d 192.168.228.140 k8s-master <none> <none>
kube-proxy-tcxkl 1/1 Running 3 (34m ago) 24d 192.168.228.141 k8s-node-1 <none> <none>
kube-scheduler-k8s-master 1/1 Running 6 (34m ago) 66d 192.168.228.140 k8s-master <none> <none>
[root@k8s-master ~]#
# 查看pod日志
# 描述指定命名空间下指定pod的详细信息
[root@k8s-master ~]# kubectl describe po calico-node-9gjl5 -n kube-system
Name: calico-node-9gjl5
Namespace: kube-system
Priority: 2000001000
Priority Class Name: system-node-critical
Node: k8s-master/192.168.228.140
Start Time: Mon, 13 May 2024 13:47:19 +0800
Labels: controller-revision-hash=5968f75c94
k8s-app=calico-node
pod-template-generation=1
Annotations: <none>
Status: Running
IP: 192.168.228.140
IPs:
IP: 192.168.228.140
Controlled By: DaemonSet/calico-node
Init Containers:
upgrade-ipam:
Container ID: docker://45bd604afb36f989369399eb577e89ff49a8284db4e9787d28ede2d0c75eaee1
Image: docker.io/calico/cni:v3.25.0
Image ID: docker-pullable://calico/cni@sha256:a38d53cb8688944eafede2f0eadc478b1b403cefeff7953da57fe9cd2d65e977
Port: <none>
Host Port: <none>
Command:
/opt/cni/bin/calico-ipam
-upgrade
State: Terminated
Reason: Completed
Exit Code: 0
Started: Thu, 06 Jun 2024 16:01:09 +0800
Finished: Thu, 06 Jun 2024 16:01:10 +0800
Ready: True
Restart Count: 3
Environment Variables from:
kubernetes-services-endpoint ConfigMap Optional: true
Environment:
KUBERNETES_NODE_NAME: (v1:spec.nodeName)
CALICO_NETWORKING_BACKEND: <set to the key 'calico_backend' of config map 'calico-config'> Optional: false
Mounts:
/host/opt/cni/bin from cni-bin-dir (rw)
/var/lib/cni/networks from host-local-net-dir (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-gg4f5 (ro)
install-cni:
Container ID: docker://9729b1de02b96152d38339c9a5bc41062ad1f8f9d1a93b340ffd178b2b6b2bdf
Image: docker.io/calico/cni:v3.25.0
Image ID: docker-pullable://calico/cni@sha256:a38d53cb8688944eafede2f0eadc478b1b403cefeff7953da57fe9cd2d65e977
Port: <none>
Host Port: <none>
Command:
/opt/cni/bin/install
State: Terminated
Reason: Completed
Exit Code: 0
Started: Thu, 06 Jun 2024 16:01:12 +0800
Finished: Thu, 06 Jun 2024 16:01:19 +0800
Ready: True
Restart Count: 0
Environment Variables from:
kubernetes-services-endpoint ConfigMap Optional: true
Environment:
CNI_CONF_NAME: 10-calico.conflist
CNI_NETWORK_CONFIG: <set to the key 'cni_network_config' of config map 'calico-config'> Optional: false
KUBERNETES_NODE_NAME: (v1:spec.nodeName)
CNI_MTU: <set to the key 'veth_mtu' of config map 'calico-config'> Optional: false
SLEEP: false
Mounts:
/host/etc/cni/net.d from cni-net-dir (rw)
/host/opt/cni/bin from cni-bin-dir (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-gg4f5 (ro)
mount-bpffs:
Container ID: docker://d7dc372279e8217478b9dc9f8c84692ab96484fcbcbd855b1342fb3e429af6a1
Image: docker.io/calico/node:v3.25.0
Image ID: docker-pullable://calico/node@sha256:a85123d1882832af6c45b5e289c6bb99820646cb7d4f6006f98095168808b1e6
Port: <none>
Host Port: <none>
Command:
calico-node
-init
-best-effort
State: Terminated
Reason: Completed
Exit Code: 0
Started: Thu, 06 Jun 2024 16:01:20 +0800
Finished: Thu, 06 Jun 2024 16:01:20 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/nodeproc from nodeproc (ro)
/sys/fs from sys-fs (rw)
/var/run/calico from var-run-calico (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-gg4f5 (ro)
Containers:
calico-node:
Container ID: docker://698d7a77b72fb6469dc9fe8e0901cdb31ab867d5c4edcf0ec10fde9ba9d00864
Image: docker.io/calico/node:v3.25.0
Image ID: docker-pullable://calico/node@sha256:a85123d1882832af6c45b5e289c6bb99820646cb7d4f6006f98095168808b1e6
Port: <none>
Host Port: <none>
State: Running
Started: Thu, 06 Jun 2024 16:01:22 +0800
Last State: Terminated
Reason: Error
Exit Code: 255
Started: Tue, 28 May 2024 11:20:45 +0800
Finished: Thu, 06 Jun 2024 16:00:35 +0800
Ready: True
Restart Count: 3
Requests:
cpu: 250m
Liveness: exec [/bin/calico-node -felix-live -bird-live] delay=10s timeout=10s period=10s #success=1 #failure=6
Readiness: exec [/bin/calico-node -felix-ready -bird-ready] delay=0s timeout=10s period=10s #success=1 #failure=3
Environment Variables from:
kubernetes-services-endpoint ConfigMap Optional: true
Environment:
DATASTORE_TYPE: kubernetes
WAIT_FOR_DATASTORE: true
NODENAME: (v1:spec.nodeName)
CALICO_NETWORKING_BACKEND: <set to the key 'calico_backend' of config map 'calico-config'> Optional: false
CLUSTER_TYPE: k8s,bgp
IP: autodetect
CALICO_IPV4POOL_IPIP: Always
CALICO_IPV4POOL_VXLAN: Never
CALICO_IPV6POOL_VXLAN: Never
FELIX_IPINIPMTU: <set to the key 'veth_mtu' of config map 'calico-config'> Optional: false
FELIX_VXLANMTU: <set to the key 'veth_mtu' of config map 'calico-config'> Optional: false
FELIX_WIREGUARDMTU: <set to the key 'veth_mtu' of config map 'calico-config'> Optional: false
CALICO_DISABLE_FILE_LOGGING: true
FELIX_DEFAULTENDPOINTTOHOSTACTION: ACCEPT
FELIX_IPV6SUPPORT: false
FELIX_HEALTHENABLED: true
Mounts:
/host/etc/cni/net.d from cni-net-dir (rw)
/lib/modules from lib-modules (ro)
/run/xtables.lock from xtables-lock (rw)
/sys/fs/bpf from bpffs (rw)
/var/lib/calico from var-lib-calico (rw)
/var/log/calico/cni from cni-log-dir (ro)
/var/run/calico from var-run-calico (rw)
/var/run/nodeagent from policysync (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-gg4f5 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
lib-modules:
Type: HostPath (bare host directory volume)
Path: /lib/modules
HostPathType:
var-run-calico:
Type: HostPath (bare host directory volume)
Path: /var/run/calico
HostPathType:
var-lib-calico:
Type: HostPath (bare host directory volume)
Path: /var/lib/calico
HostPathType:
xtables-lock:
Type: HostPath (bare host directory volume)
Path: /run/xtables.lock
HostPathType: FileOrCreate
sys-fs:
Type: HostPath (bare host directory volume)
Path: /sys/fs/
HostPathType: DirectoryOrCreate
bpffs:
Type: HostPath (bare host directory volume)
Path: /sys/fs/bpf
HostPathType: Directory
nodeproc:
Type: HostPath (bare host directory volume)
Path: /proc
HostPathType:
cni-bin-dir:
Type: HostPath (bare host directory volume)
Path: /opt/cni/bin
HostPathType:
cni-net-dir:
Type: HostPath (bare host directory volume)
Path: /etc/cni/net.d
HostPathType:
cni-log-dir:
Type: HostPath (bare host directory volume)
Path: /var/log/calico/cni
HostPathType:
host-local-net-dir:
Type: HostPath (bare host directory volume)
Path: /var/lib/cni/networks
HostPathType:
policysync:
Type: HostPath (bare host directory volume)
Path: /var/run/nodeagent
HostPathType: DirectoryOrCreate
kube-api-access-gg4f5:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: Burstable
Node-Selectors: kubernetes.io/os=linux
Tolerations: :NoSchedule op=Exists
:NoExecute op=Exists
CriticalAddonsOnly op=Exists
node.kubernetes.io/disk-pressure:NoSchedule op=Exists
node.kubernetes.io/memory-pressure:NoSchedule op=Exists
node.kubernetes.io/network-unavailable:NoSchedule op=Exists
node.kubernetes.io/not-ready:NoExecute op=Exists
node.kubernetes.io/pid-pressure:NoSchedule op=Exists
node.kubernetes.io/unreachable:NoExecute op=Exists
node.kubernetes.io/unschedulable:NoSchedule op=Exists
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SandboxChanged 33m kubelet Pod sandbox changed, it will be killed and re-created.
Normal Created 33m kubelet Created container upgrade-ipam
Normal Pulled 33m kubelet Container image "docker.io/calico/cni:v3.25.0" already present on machine
Normal Started 33m kubelet Started container upgrade-ipam
Normal Pulled 33m kubelet Container image "docker.io/calico/cni:v3.25.0" already present on machine
Normal Created 33m kubelet Created container install-cni
Normal Started 33m kubelet Started container install-cni
Normal Created 33m kubelet Created container mount-bpffs
Normal Pulled 33m kubelet Container image "docker.io/calico/node:v3.25.0" already present on machine
Normal Started 33m kubelet Started container mount-bpffs
Normal Pulled 33m kubelet Container image "docker.io/calico/node:v3.25.0" already present on machine
Normal Created 33m kubelet Created container calico-node
Normal Started 33m kubelet Started container calico-node
Warning Unhealthy 33m (x2 over 33m) kubelet Readiness probe failed: calico/node is not ready: BIRD is not ready: Error querying BIRD: unable to connect to BIRDv4 socket: dial unix /var/run/bird/bird.ctl: connect: no such file or directory
Warning Unhealthy 33m kubelet Readiness probe failed: 2024-06-06 08:01:26.815 [INFO][161] confd/health.go 180: Number of node(s) with BGP peering established = 1
calico/node is not ready: BIRD is not ready: BGP not established with 192.168.228.141
[root@k8s-master ~]#
4. 查看deploy
# 添加-o wide参数可以输出更详细的信息
[root@k8s-master ~]# kubectl get deploy -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx 0/1 1 0 24d nginx nginx app=nginx
[root@k8s-master ~]#
5. 查看应用信息
# 添加-o wide参数可以输出更详细的信息
[root@k8s-master ~]# kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 66d <none>
nginx NodePort 10.102.152.54 <none> 80:32251/TCP 24d app=nginx
[root@k8s-master ~]#
6. 查看组合信息
[root@k8s-master ~]# kubectl get no,ns,svc,deploy,po -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
node/k8s-master Ready control-plane,master 65d v1.23.6 192.168.228.140 <none> CentOS Linux 7 (Core) 3.10.0-1160.114.2.el7.x86_64 docker://20.10.0
node/k8s-node-1 Ready <none> 24d v1.23.6 192.168.228.141 <none> CentOS Linux 7 (Core) 3.10.0-1160.114.2.el7.x86_64 docker://20.10.0
node/k8s-node-2 Ready <none> 24d v1.23.6 192.168.228.142 <none> CentOS Linux 7 (Core) 3.10.0-1160.114.2.el7.x86_64 docker://20.10.0
NAME STATUS AGE
namespace/default Active 65d
namespace/kube-node-lease Active 65d
namespace/kube-public Active 65d
namespace/kube-system Active 65d
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 65d <none>
service/nginx NodePort 10.102.152.54 <none> 80:32251/TCP 24d app=nginx
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/nginx 0/1 1 0 24d nginx nginx app=nginx
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/nginx-85b98978db-r7krm 0/1 ImagePullBackOff 1 (16m ago) 23d 10.244.109.77 k8s-node-1 <none> <none>
[root@k8s-master ~]#
高级命令
1.
2.