k8s常用命令
# 命令行工具 (kubectl)
# 获取node节点相关信息
# 获取节点和服务版本信息
kubectl get nodes/node
# 获取节点和服务版本信息,并查看附加信息
kubectl get nodes/node -o wide
1
2
3
4
2
3
4
# 命名空间
# 创建 namespace test
kubectl create ns test
# 删除 namespace test
kubectl delete ns test
1
2
3
4
2
3
4
# 获取pod节点相关信息
# 获取所有名称空间的pod
kubectl get pod -A
# 获取pod信息,默认是default名称空间
kubectl get pod
# 获取pod信息,并查看附加信息
kubectl get pod -o wide
# 获取指定名称空间的pod
kubectl get pod -n xxx
# 查看pod的详细信息,以yaml格式或json格式显示
kubectl get pods -o yaml/json
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 获取service相关信息
# 获取默认是default名称空间的service
kubectl get services
# 获取指定名称空间的service
kubectl get services -n xxx
1
2
3
4
2
3
4
# 获取pod状态信息
# 查看pod
kubectl describe pod pod-name -n namespace
(kubectl describe pod calico-node-kh6fd -n kube-system)
# 强制删除pod
kubectl delete pod pod-name -n namespace --grace-period=0 --force
kubectl delete pod invoice-aisino-64b68697dd-7b8bj -n invoice-management --grace-period=0 --force
kubectl delete pod invoice-external-api-79c9c5b88-4hnpl -n invoice-management --grace-period=0 --force
kubectl delete pod invoice-gateway-569cdf6d4-88qlf -n invoice-management --grace-period=0 --force
(kubectl delete pod calico-node-fjbf9 -n kube-system --force)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# node调度处理命令
https://blog.csdn.net/u011628753/article/details/127290768
# 暂停调度
## 暂停node调度,使node不可用,使node不接收新的pod
kubectl cordon <node-name>
# 驱逐pod
## 把pod从node上赶走
kubectl drain <node-name>
# 恢复调度
## 取消node暂停调度状态,使node可以接收调度
kubectl uncordon <node-name>
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 部署应用(yaml文件)
kubectl apply -f xxx.yaml
1
# k8s中Pod基本使用
https://blog.csdn.net/qq_30038621/article/details/125208395
1
# 防火墙问题 重启kubelet
firewall-cmd --state
sudo systemctl stop firewalld
swapoff -a
systemctl restart kubelet
1
2
3
4
2
3
4
# 运行时 is down
systemctl status containerd
systemctl status docker
systemctl restart containerd
systemctl restart docker
1
2
3
4
5
2
3
4
5
# K8S 查询节点上运行的 Pod
kubectl get pod --field-selector spec.nodeName='k8s-cloud2-node4' --all-namespaces -o wide
1
#
kubectl exec -it customer-management-front-6f9c649c5-7r4wf /bin/bash
# kubectl exec -it customer-management-front-6f9c649c5-7r4wf /bin/sh
1
2
2