這是本文件的舊版!
Kubctl 語法整理
顯示 K8S 內的 POD 清單
kubectl get pod
Exp.
localadmin@iiidevops-73:~$ kubectl get pod NAME READY STATUS RESTARTS AGE devopsapi-dbbcf7fd4-j5nv2 1/1 Running 0 36m devopsdb-5555449b8d-rd2z9 1/1 Running 0 37m devopsui-84496c7fcc-bd99r 1/1 Running 0 126m redmine-547cbdbbbb-wk9s6 1/1 Running 1 17h redmine-postgresql-6fb9475c6c-gs9gh 1/1 Running 0 17h sonarqube-server-6ccbf4c54f-vksmp 1/1 Running 0 17h
顯示 K8S 內 POD 的 logs
kubectl logs [pod NAME]
Exp.
localadmin@iiidevops-73:~$ kubectl logs redmine-547cbdbbbb-wk9s6 | tail -20 I, [2020-12-21T10:47:03.089762 #1] INFO -- : Rendered enumerations/_form.html.erb (2.8ms) I, [2020-12-21T10:47:03.090267 #1] INFO -- : Rendered enumerations/new.html.erb within layouts/admin (4.2ms) I, [2020-12-21T10:47:03.095432 #1] INFO -- : Rendered admin/_menu.html.erb (4.9ms) I, [2020-12-21T10:47:03.095745 #1] INFO -- : Rendering layouts/base.html.erb I, [2020-12-21T10:47:03.107140 #1] INFO -- : Rendered layouts/base.html.erb (11.3ms) I, [2020-12-21T10:47:03.107464 #1] INFO -- : Completed 200 OK in 32ms (Views: 19.9ms | ActiveRecord: 5.8ms) I, [2020-12-21T10:47:05.101236 #1] INFO -- : Started POST "/enumerations" for 10.20.0.74 at 2020-12-21 10:47:05 +0000 I, [2020-12-21T10:47:05.102407 #1] INFO -- : Processing by EnumerationsController#create as HTML I, [2020-12-21T10:47:05.102487 #1] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"wRaItdciacpkIjcxxxxxxxxxxrdQWdKf66WuZPq6AGAIQyK9BLeuyOlyKODKQedaCNdAoADOadTy+3UH4mTeg==", "enumeration"=>{"type"=>"IssuePriority", "name"=>"Low", "active"=>"1", "is_default"=>"0"}, "commit"=>"Create"} I, [2020-12-21T10:47:05.112128 #1] INFO -- : Current user: admin (id=1) I, [2020-12-21T10:47:05.192218 #1] INFO -- : Redirected to http://10.20.0.74:32748/enumerations I, [2020-12-21T10:47:05.192469 #1] INFO -- : Completed 302 Found in 90ms (ActiveRecord: 17.5ms) 10.20.0.74 - - [21/Dec/2020:10:47:05 UTC] "POST /enumerations HTTP/1.1" 302 102 http://10.20.0.74:32748/enumerations/new?type=IssuePriority -> /enumerations 10.20.0.74 - - [21/Dec/2020:10:47:05 UTC] "GET /enumerations HTTP/1.1" 200 8526 http://10.20.0.74:32748/enumerations/new?type=IssuePriority -> /enumerations 10.20.0.74 - - [22/Dec/2020:02:21:47 UTC] "GET /users/current.json HTTP/1.1" 200 253 - -> /users/current.json 10.20.0.74 - - [22/Dec/2020:02:21:47 UTC] "GET /users.json?offset=0&limit=25&key=d64c31axxxxxxxxxxd085fc5825ec257b31a3ec7 HTTP/1.1" 200 230 - -> /users.json?offset=0&limit=25&key=d64c31aff3xxxxxxxxxx5fc5825ec257b31a3ec7
顯示 K8S 內 POD 的描述資訊
kubectl describe pod [pod NAME]
Exp.
localadmin@iiidevops-71:~/deploy-devops$ kubectl describe pod devopsapi-cdccbcb48-qv4n9 Name: devopsapi-cdccbcb48-qv4n9 Namespace: default Priority: 0 Node: iiidevops-72/10.20.0.72 Start Time: Thu, 24 Dec 2020 06:27:37 +0000 Labels: app=devopsapi pod-template-hash=cdccbcb48 : : Normal Pulling 15s (x2 over 38s) kubelet Pulling image "iiiorg/devops-api:develop" Warning Failed 11s (x2 over 34s) kubelet Failed to pull image "iiiorg/devops-api:develop": rpc error: code = Unknown desc = Error response from daemon: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit Warning Failed 11s (x2 over 34s) kubelet Error: ErrImagePull
進入一個 POD 內操作
kubectl exec -it [POD Name] bash
Exp.
localadmin@iiidevops-73:~/deploy-devops$ kubectl exec -it devopsapi-c9ddc8cdf-mrb9f bash kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead. root@devopsapi-c9ddc8cdf-mrb9f:/usr/src/app# ls -lt total 108 -rw-r--r-- 1 root root 30115 Dec 22 09:36 devops-api-rotate.log drwxr-xr-x 1 root root 4096 Dec 22 09:24 apis -rwxr-xr-x 1 root root 2052 Dec 22 09:22 alembic.ini -rw-r--r-- 1 root root 41 Dec 21 22:15 git_commit -rwxr-xr-x 1 root root 401 Dec 21 22:15 Dockerfile -rwxr-xr-x 1 root root 11357 Dec 21 22:15 LICENSE -rwxr-xr-x 1 root root 878 Dec 21 22:15 README.md -rwxr-xr-x 1 root root 1994 Dec 21 22:15 _alembic.ini -rwxr-xr-x 1 root root 886 Dec 21 22:15 _environments.json -rwxr-xr-x 1 root root 360 Dec 21 22:15 _k8s_config drwxr-xr-x 2 root root 4096 Dec 21 22:15 docs drwxr-xr-x 3 root root 4096 Dec 21 22:15 iiidevops drwxr-xr-x 2 root root 4096 Dec 21 22:15 k8s-yaml -rwxr-xr-x 1 root root 179 Dec 21 22:15 requirements.txt -rwxr-xr-x 1 root root 1342 Dec 21 22:15 environments.json -rwxr-xr-x 1 root root 3133 Dec 21 22:15 k8s_config root@devopsapi-c9ddc8cdf-mrb9f:/usr/src/app#
顯示 K8S 內的 deploy 清單
kubctl get deploy
Exp.
localadmin@iiidevops-73:~$ kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE devopsapi 1/1 1 1 17h devopsdb 1/1 1 1 37m devopsui 1/1 1 1 17h redmine 1/1 1 1 17h redmine-postgresql 1/1 1 1 17h sonarqube-server 1/1 1 1 17h
移除 K8S 內的 deploy pod
kubctl delete deploy [deploy NAME]
Exp.
localadmin@iiidevops-73:~$ kubectl delete deploy devopsui devopsdb devopsapi deployment.apps "devopsui" deleted deployment.apps "devopsdb" deleted deployment.apps "devopsapi" deleted