$ kubeadm token list TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS 8ca35s.butdpihinkdczvqb 19h 2022-09-14T02:54:55Z authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token
使用标签选择器列出 Pod 具体用法可以参考帮助信息 kubectl get --help | grep '\-l'
node
查看 node 信息
$ kubectl get nodes NAME STATUS ROLES AGE VERSION ops-kubernetes1 Ready control-plane 5h31m v1.25.0 ops-kubernetes2 Ready <none> 3h6m v1.25.0 ops-kubernetes3 Ready <none> 179m v1.25.0
查看指定节点的状态及其他详细信息
kubectl describe node <节点名称>
标记 node 为不可调度
如果标记节点为不可调度(unschedulable),将阻止新 Pod 调度到该 Node 之上, 但不会影响任何已经在其上的 Pod。
kubectl cordon $NODENAME
检查集群控制组件的健康状态
API 服务器对外暴露了一个名为 componentstatuses 的 API 资源,用来显示每个控制平面组件的健康状态。可以通过以下命令列出各个控制平面组件的健康状态
$ kubectl get componentstatuses Warning: v1 ComponentStatus is deprecated in v1.19+ NAME STATUS MESSAGE ERROR controller-manager Healthy ok scheduler Healthy ok etcd-0 Healthy {"health":"true","reason":""}
$ kubectl get pod -n test -l app NAME READY STATUS RESTARTS AGE testpod-admin-698bfc4998-8mccv 1/1 Running 0 8d testpod-api-748dc4bf87-dptbb 1/1 Running 0 38d testpod-api-748dc4bf87-xnsbr 1/1 Running 0 7d3h testpod-front-58796b88f7-k58sz 1/1 Running 0 8d testpod-search-d6bd6996c-dcfgq 1/1 Running 0 8d
以下示例,选择没有标签app 的 Pod。
kubectl get pod -n test -l '!app'
以下示例,选择符合标签和值app=testpod-api 的 Pod
$ kubectl get pod -n test -l app=testpod-api NAME READY STATUS RESTARTS AGE testpod-api-748dc4bf87-dptbb 1/1 Running 0 38d testpod-api-748dc4bf87-xnsbr 1/1 Running 0 7d3h
以下示例,选择具体有标签 app,但是值不为 testpod-api 的 Pod
$ kubectl get pod -n test -l app!=testpod-api NAME READY STATUS RESTARTS AGE testpod-admin-698bfc4998-8mccv 1/1 Running 0 8d testpod-front-58796b88f7-k58sz 1/1 Running 0 8d testpod-search-d6bd6996c-dcfgq 1/1 Running 0 8d
以下示例,列出拥有标签 app,且其值为 testpod-api 或者 testpod-front 的 Pod
$ kubectl get pod -n test -l 'app in (testpod-api,testpod-front)' NAME READY STATUS RESTARTS AGE testpod-api-748dc4bf87-dptbb 1/1 Running 0 38d testpod-api-748dc4bf87-xnsbr 1/1 Running 0 7d3h testpod-front-58796b88f7-k58sz 1/1 Running 0 8d
以下示例,列出拥有标签 app,且其值不为 testpod-api 或者 testpod-front 的 Pod
$ kubectl get pod -n test -l 'app notin (testpod-api,testpod-front)' NAME READY STATUS RESTARTS AGE testpod-admin-698bfc4998-8mccv 1/1 Running 0 8d testpod-search-d6bd6996c-dcfgq 1/1 Running 0 8d
$ kubectl get pod -n test -l 'app=testpod-api,project=testpod' NAME READY STATUS RESTARTS AGE testpod-api-748dc4bf87-dptbb 1/1 Running 0 38d testpod-api-748dc4bf87-xnsbr 1/1 Running 0 7d3h
证书管理
查看集群证书过期时间
# kubeadm certs check-expiration [check-expiration] Reading configuration from the cluster... [check-expiration] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED admin.conf Sep 24, 2024 08:15 UTC 364d no apiserver Sep 24, 2024 07:21 UTC 364d ca no apiserver-etcd-client Sep 24, 2024 07:21 UTC 364d etcd-ca no apiserver-kubelet-client Sep 24, 2024 07:21 UTC 364d ca no controller-manager.conf Sep 24, 2024 07:21 UTC 364d no etcd-healthcheck-client Sep 24, 2024 07:21 UTC 364d etcd-ca no etcd-peer Sep 24, 2024 07:21 UTC 364d etcd-ca no etcd-server Sep 24, 2024 07:21 UTC 364d etcd-ca no front-proxy-client Sep 24, 2024 07:21 UTC 364d front-proxy-ca no scheduler.conf Sep 24, 2024 07:21 UTC 364d no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED ca Sep 19, 2032 05:55 UTC 8y no etcd-ca Sep 19, 2032 05:55 UTC 8y no front-proxy-ca Sep 19, 2032 05:55 UTC 8y no
kube-proxy 负责 Service 到后端 Pod 的转发规则管理,默认使用 iptables,可选模式还包括 IPVS 和 userspace (性能太差,几乎不使用),要查看节点使用的 kube-proxy 模式,可以执行以下命令查看
$ kubectl get nodes NAME STATUS ROLES AGE VERSION kubernetes-node-6jst Ready <none> 2h v1.13.0 kubernetes-node-cx31 Ready <none> 2h v1.13.0 kubernetes-node-jj1t Ready <none> 2h v1.13.0