一、接9.11
19、部署calico的pod
4. 查看容器和节点状态
异常处理:
出现Init:0/3,查看node节点 /var/log/messages是否有除网络异常之外的报错信息
三台机器执行:(更新版本)
yum list kernel
yum update kernel
reboot
三台机器该目录下要有以下文件
reboot
kubectl get po -A 查看没有pending状态就等待
[root@k8s-master ~]# kubectl get node
NAME STATUS ROLES AGE VERSION k8s-master Ready control-plane 18h v1.28.2 k8s-node1 Ready <none> 18h v1.28.2 k8s-node2 Ready <none> 18h v1.28.2
[root@k8s-master ~]# kubectl run nginx --image=nginx:latest //添加一个新的pod
pod/nginx created[root@k8s-master ~]# kubectl run nginx0 --image=nginx
[root@k8s-master ~]# kubectl get po -Aowide | grep nginxdefault nginx 1/1 Running 0 47m 172.16.169.130 k8s-node2 <none> <none> default nginx1 1/1 Running 0 38m 172.16.169.129 k8s-node2 <none> <none>
[root@k8s-master ~]# kubectl logs nginx //查看日志
[root@k8s-master ~]# curl 172.16.169.130
[root@k8s-master ~]# kubectl delete pod nginx
[root@k8s-master ~]# kubectl delete pod nginx1
20、 资源监控Metrics 部署
1. 复制证书到所有节点
[root@k8s-master ~]# scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-node1:/etc/kubernetes/pki/front-proxy-ca.crt
[root@k8s-master ~]# scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-node2:/etc/kubernetes/pki/front-proxy-ca.crt
2. 上传components.yaml文件
[root@k8s-master ~]# mkdir pods
[root@k8s-master ~]# mv components.yaml pods/
[root@k8s-master ~]# cd pods/
[root@k8s-master pods]# ls
components.yaml
3. 根据yaml文件创建pod
[root@k8s-master pods]# kubectl create -f components.yaml
4. 查看pod列表状态
[root@k8s-master pods]# kubectl get pods -Aowide | grep metrics
kube-system metrics-server-79776b6d54-rlw2j 1/1 Running 0 5m30s 172.16.36.65 k8s-node1 <none> <none>
5. 查看节点资源监控
[root@k8s-master pods]# kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% k8s-master 143m 7% 1103Mi 64% k8s-node1 41m 2% 819Mi 47% k8s-node2 45m 2% 858Mi 49%
[root@k8s-master pods]# kubectl top pods -n kube-system //查看kube-system命名空间的所有节点
NAME CPU(cores) MEMORY(bytes) calico-kube-controllers-6d48795585-dnwc4 2m 31Mi calico-node-4dfpr 22m 124Mi calico-node-64rzl 24m 103Mi calico-node-t8l7f 22m 92Mi coredns-6554b8b87f-4xzkp 1m 16Mi coredns-6554b8b87f-ws7pj 1m 28Mi etcd-k8s-master 17m 65Mi kube-apiserver-k8s-master 51m 315Mi kube-controller-manager-k8s-master 14m 86Mi kube-proxy-hgn9q 1m 33Mi kube-proxy-tshb8 1m 26Mi kube-proxy-ww7k4 1m 36Mi kube-scheduler-k8s-master 3m 43Mi metrics-server-79776b6d54-rlw2j 3m 17Mi
21、Dashboard部署
1. 建⽴dashboard的pod资源
[root@k8s-master ~]# cd k8s-ha-install/
[root@k8s-master k8s-ha-install]# ls
[root@k8s-master k8s-ha-install]# cd dashboard/
[root@k8s-master dashboard]# ls
dashboard-user.yaml dashboard.yaml[root@k8s-master dashboard]# kubectl create -f . //使用当前目录
[root@k8s-master dashboard]# kubectl get po -A| grep dashboard
2. 设置svc模式
[root@k8s-master dashboard]# kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
[root@k8s-master dashboard]# kubectl get svc kubernetes-dashboard -n kubernetes-dashboard //获取端口
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes-dashboard NodePort 10.96.22.191 <none> 443:31282/TCP 8m48s
3. 获得token
[root@k8s-master dashboard]# kubectl create token admin-user -n kube-system
eyJhbGciOiJSUzI1NiIsImtpZCI6IlhPdHNYNThidExFTHNMNmR4QkRuMGd1TWhqd3VYaW9rc2lHN3o1Y2RMdDQifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzI2MTE1NTA4LCJpYXQiOjE3MjYxMTE5MDgsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiYjRkZDAzZDMtNTk3Yy00YTEwLTg5MTUtMGJmYzJiOTBiODA1In19LCJuYmYiOjE3MjYxMTE5MDgsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTphZG1pbi11c2VyIn0.cvypVYVBNb8CkvXZv1lZ8CXY7lIbzsvyFXK7ovke5uWpiBm8_3xNBwcxFUEA9nk2MuA36Ru2U9z6Qs2TJb06mPK308wu5GQIXAai3i5ABw5i5nkhDuKIoJpcyvnCALKPDDIg6oIp_BjnGzo8aTDiH6g53lGUKZHDBwfFehkVNucR2BvRny1yeBXWXpiyM4SHvyvCa0INtlDCSv4jkk8-ag_G8VRtxEE1LqO1I39dV8HUhBmC7_gKItrMaVmsGa3btkTuynGOqxHSP_DtHjVnQH8GiSyszqDceBVIqeWsULTZFUjBoR51Ef76Uxv2JqnYvgYOatbGU0bvu9k_BV0vvQ
22、设置proxy的模式为ipvs
1. 编辑pod
[root@k8s-master ~]# kubectl edit cm kube-proxy -n kube-system
2. 更新 Kube-Proxy 的 Pod
[root@k8s-master ~]# kubectl patch daemonset kube-proxy -p "{\"spec\":{\"template\":{\"metadata\": {\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}" -n kube-system
daemonset.apps/kube-proxy patched
3. 访问测试
[root@k8s-master ~]# curl 127.0.0.1:10249/proxyMode
ipvs
23、查看service pod 宿主机的网段
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h[root@k8s-master ~]# kubectl get pods -Aowide
24、验证是否可正常创建参数
[root@k8s-master ~]# kubectl create deploy cluster-test1 --image=registry.cn-beijing.aliyuncs.com/dotbalo/debug-tools -- sleep 3600
[root@k8s-master ~]# kubectl get po
[root@k8s-master ~]# kubectl get po -owidew
25、Pod 必须能够解析 Service
1. nslookup kubernetes
[root@k8s-master ~]# kubectl exec -it cluster-test1-54575cf56c-65tv4 -- bash
(07:39 cluster-test1-54575cf56c-65tv4:/) nslookup kubernetes
Server: 10.96.0.10
Address: 10.96.0.10#53Name: kubernetes.default.svc.cluster.local
Address: 10.96.0.1
2. nslookup kube-dns.kube-system
(07:39 cluster-test1-54575cf56c-65tv4:/) nslookup kube-dns.kube-system
Server: 10.96.0.10
Address: 10.96.0.10#53Name: kube-dns.kube-system.svc.cluster.local
Address: 10.96.0.10可以解析到server的第⼗个ip,说明可以解析到kube-dns,说 明跨namespace也可解析
26、 确认各 Pod 之间是否可正常通信
[root@k8s-master ~]# kubectl exec -it cluster-test1-54575cf56c-65tv4 -- bash
(07:46 cluster-test1-54575cf56c-65tv4:/) ping 172.16.235.200 -c 3
PING 172.16.235.200 (172.16.235.200) 56(84) bytes of data.
64 bytes from 172.16.235.200: icmp_seq=1 ttl=62 time=0.553 ms
64 bytes from 172.16.235.200: icmp_seq=2 ttl=62 time=0.675 ms
64 bytes from 172.16.235.200: icmp_seq=3 ttl=62 time=0.631 ms--- 172.16.235.200 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.553/0.619/0.675/0.058 ms
二、 kubernetes常用命令
1、kubernetes自动补齐
[root@k8s-master ~]# yum -y install bash-completion
[root@k8s-master ~]# source <(kubectl completion bash) //临时开启自动补齐功能
[root@k8s-master ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc //永久开启
2、基础命令
1. 创建
[root@k8s-master ~]# kubectl create namespace pes
namespace/pes created
[root@k8s-master ~]# kubectl get namespaceNAME STATUS AGE default Active 24h kube-node-lease Active 24h kube-public Active 24h kube-system Active 24h kubernetes-dashboard Active 4h41m pes Active 38s
2. 删除
NAMESPACE NAME READY STATUS RESTARTS AGE default cluster-test1-54575cf56c-65tv4 1/1 Running 0 24m default clustertest-58dbff6c48-xbpvj 0/1 ErrImagePull 0 38m
[root@k8s-master ~]# kubectl delete deployment clustertest //删除
3、编写yaml文件
[root@k8s-master ~]# vim pods/abc.yaml
apiVersion: v1 kind: Pod metadata:name: busybox-sleep spec:containers:- name: busyboximage: busybox:1.28args:- sleep- "1000"
4. kubectl create
[root@k8s-master pods]# kubectl create -f abc.yaml
[root@k8s-master pods]# kubectl get po -A | grep bus
default busybox-sleep 0/1 ImagePullBackOff 0 11m
[root@k8s-master pods]# kubectl delete pod busybox-sleep
pod "busybox-sleep" deleted
[root@k8s-master pods]# kubectl get po -A | grep bus