k8s 命令行记录

删除批量失败的pod

1
kubectl  get pods -n network | grep Evicted | awk '{print$1}'| xargs kubectl delete -n network pods

获取k8s token

1
2

kubectl describe secret $(kubectl get secret -n kube-system |grep admin|awk '{print $1}')  -n kube-system|grep '^token'|awk '{print $2}'

卸载k8s

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
rm -rf /var/lib/rook/
rm -rf /var/lib/kubelet/plugins/rook-ceph.*
rm -rf /var/lib/kubelet/plugins_registry/
systemctl restart containerd
systemctl restart kubelet
# install k8s
kubectl apply -f common.yaml  -f crds.yaml -f operator.yaml
watch kubectl get po -n rook-ceph
dd if=/dev/zero of=/dev/sdb bs=1M status=progress
# 针对secret没有的情况下创建的
kubectl -n rook-ceph create secret generic rook-ceph-crash-collector-keyring

[root@k8s-6-m1 ~]# kubectl get pod -n network
NAME                                      READY   STATUS    RESTARTS     AGE
ddm-457212190575931393-789596c79f-mdgtv   1/1     Running   0            3d2h
ddm-457226249408565249-5557bcc97b-zz25c   1/1     Running   0            3d2h
ddm-457241104516276225-7dc9b678cb-f8nwk   1/1     Running   0            3d2h
ddm-457263124217548801-7df88c8b5c-j55ps   1/1     Running   0            3d2h
ddm-457322858648690689-59dbddcc9b-49469   1/1     Running   0            3d2h
mme-test-56c4b7d4f7-sfddr                 1/1     Running   1 (4d ago)   10d
[root@k8s-6-m1 ~]# kubectl exec -it ddm-457241104516276225-7dc9b678cb-f8nwk --bash
error: unknown flag: --bash
See 'kubectl exec --help' for usage.
[root@k8s-6-m1 ~]# kubectl exec -it ddm-457241104516276225-7dc9b678cb-f8nwk -- /bin/bash
Error from server (NotFound): pods "ddm-457241104516276225-7dc9b678cb-f8nwk" not found
[root@k8s-6-m1 ~]# kubectl exec -it ddm-457241104516276225-7dc9b678cb-f8nwk -n network  -- /bin/bash
[root@ddm-457241104516276225-7dc9b678cb-f8nwk /]# top
top - 11:31:52 up 4 days, 10 min,  0 users,  load average: 2.63, 3.76, 4.11
Tasks:  11 total,   1 running,  10 sleeping,   0 stopped,   0 zombie
%Cpu(s):  7.2 us, 14.4 sy,  0.0 ni, 78.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 32780156 total, 10043196 free, 13416372 used,  9320588 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 16440100 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
   13 root       0 -20 2514916   1.2g   4928 S  40.0  3.8   1734:53 modem_m
   12 root      20   0  756868   9092   3392 S   6.7  0.0 250:21.96 kafka
    1 root      20   0   11692   1452   1204 S   0.0  0.0   0:00.04 docker_ddm_star
   17 root      20   0   11700   1472   1216 S   0.0  0.0   2:40.46 process_watchdo
  543 root      20   0   11832   1944   1496 S   0.0  0.0   0:00.02 bash
 2583 root      20   0   11832   1892   1448 S   0.0  0.0   0:00.00 bash
 7088 root      20   0    4368    360    280 S   0.0  0.0   0:00.00 sleep
17949 root      20   0   11832   1948   1496 S   0.0  0.0   0:00.00 bash
32170 root      20   0   11832   1896   1448 S   0.0  0.0   0:00.00 bash
32228 root      20   0    4368    356    280 S   0.0  0.0   0:00.00 sleep
32229 root      20   0   56212   1996   1424 R   0.0  0.0   0:00.00 top
#k8s 查看crds
crds=$(for i in `kubectl get crd --no-headers | awk -F"." '{print $1}'`;do echo -n "$i|";done | sed 's/|$//g')
kubectl api-resources | grep -vE ${crds}
Licensed under CC BY-NC-SA 4.0
最后更新于 Dec 31, 2024 09:01 UTC
comments powered by Disqus
Built with Hugo
主题 StackJimmy 设计