Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the management methods of kubectl in kubernetes

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

This article will share with you how to manage kubectl in kubernetes. The article covers kubectl declarative management method, kubectl declarative management method and the core resource introduction of kubectl. I hope you can get something through this article.

1. Kubectl declarative management method kubectl Xiaojie: kubectl is an official CLI command line tool, which is used for apiserver to communicate, organize and transform the commands entered by users on the command line into information that apiserver can recognize, and then realize an effective way to manage various resources of K8s. 1 、 View all the namespaces of the current cluster [root@test-nodes1 ~] # kubectl get namespaceNAME STATUS AGEdefault Active 42hkube-node-lease Active 42hkube-public Active 42hkube-system Active 42hMurray- -- 2. View all resources under the default namespace [root@test-nodes1 ~] # kubectl get all-n defaultNAME READY STATUS RESTARTS AGEpod/nginx-ds-76fr8 0 ImagePullBackOff 0 39hpod/nginx-ds-zz7jn 0 39hpod/nginx-ds1-qg45q 1 ErrImagePull 0 39hpod/nginx-ds1-qg45q 1 39hpod/nginx-ds1-whnmv 1 Running 0 39h#pod Resource NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEservice/kubernetes ClusterIP 192.168.0.1 443/TCP 42h#service Resource NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGEdaemonset.apps/nginx-ds 2 2 0 20 39hdaemonset.apps/nginx-ds1 22 22 22 39h#pod controller -- 3. Create and delete the namespace [root@test-nodes1 ~] # kubectl create namespace testnamespace/test created [root@test-nodes1 ~] # kubectl get namespaceNAME STATUS AGEdefault Active 42hkube-node-lease Active 42hkube-public Active 42hkube-system Active 42htest Active 6s [root@test-nodes1 ~] # kubectl delete namespace testnamespace "test" deleted- -4. Create a deployment (pods controller) resource [root@test-nodes1 ~] # kubectl create deployment nignx-dp-- image=test-harbor.cedarhd.com/public/nginx:v1.7.9-n kube-publicdeployment.apps/nignx-dp created -- 5. View the deployment resource controller under the kube-public namespace [root@test-nodes1 ~] # kubectl get deployment-n kube-publicNAME READY UP-TO-DATE AVAILABLE AGEnignx-test 0Universe 11070sMurray- -- 6. Check the operation of pods under the kube-public namespace [root@test-nodes1 ~] # kubectl get deployment-n kube-publicNAME READY UP-TO-DATE AVAILABLE AGEnignx-test 1Universe 1 1 1 21sMurray- -- 7 View pods resources in kube-public space [root@test-nodes1 ~] # kubectl get pods-n kube-public-o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnignx-dp-7f6d4979bd-nnc57 0 ImagePullBackOff 0 13m 172.7.21.4 test-nodes1.cedarhd.com Nignx-test-655d6fbcb5-r9t57 1 Running 0 4m1s 172.7.22.4 test-nodes2.cedarhd.com -8. Curl 172.7.22.4 nginx [root@test-nodes2 ~] # curl 172.7.22.4Welcome to nginx on the test-nodes2.cedarhd.com node! Body {width: 35eme; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.

Thank you for using nginx.

-9. View specific pods (nginx-test) details under deployment [root@test-nodes1 ~] # kubectl describe deployment nignx-test-n kube-publicName: nignx-testNamespace: kube-publicCreationTimestamp: Mon 03 Feb 2020 02:02:59-0500Labels: app=nignx-testAnnotations: deployment.kubernetes.io/revision: 1Selector: app=nignx-testReplicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailableStrategyType: RollingUpdateMinReadySeconds: 0RollingUpdateStrategy: 25 max unavailable 25% max surgePod Template: Labels: app=nignx-test Containers: nginx: Image: test-harbor.cedarhd.com/public/nginx:v1.7.9 Port: Host Port: Environment: Mounts: Volumes: Conditions: Type Status Reason-Available True MinimumReplicasAvailable Progressing True NewReplicaSetAvailableOldReplicaSets: NewReplicaSet: nignx-test-655d6fbcb5 (1 replicas created) Events: Type Reason Age From Message-Normal ScalingReplicaSet 22m deployment-controller Scaled up replica set nignx-test-655d6fbcb5 to 1- -10. Enter the nginx-test pod resource [root@test-nodes1 ~] # kubectl get pods-n kube-publicNAME READY STATUS RESTARTS AGEnignx-test-655d6fbcb5-r9t57 1 root@nignx-test-655d6fbcb5-r9t57 1 Running 0 24m [root@test-nodes1 ~] # kubectl exec-ti nignx-test-655d6fbcb5-r9t57 / bin/bash-n kube-public# is the same as the docker operation method root@nignx-test-655d6fbcb5-r9t57 : / # ip addr1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever12: eth0@if13: mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:07:16:04 brd ff:ff:ff:ff:ff:ff inet 172.7.22.4/24 Brd 172.7.22.255 scope global eth0 valid_lft forever preferred_lft forever-11 、 Delete pod resources (i.e. restart) [root@test-nodes1 ~] # kubectl delete pod nignx-test-655d6fbcb5-r9t57-n kube-publicpod "nignx-test-655d6fbcb5-r9t57" deleted [root@test-nodes1 ~] # kubectl get pods-n kube-public-o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnignx-dp-7f6d4979bd-nnc57 0 / 1 ImagePullBackOff 0 40m 172.7.21.4 test-nodes1.cedarhd.com nignx-test-655d6fbcb5-c42z8 1 Running 0 18s 172.7.21.5 test-nodes1.cedarhd.com-- -12. Delete deployment [root@test-nodes1 ~] # kubectl get deploy-n kube-publicNAME READY UP-TO-DATE AVAILABLE AGEnignx-dp 0 53mnignx-test 1 1 10 53mnignx-test 1 1 1 36m [root@test-nodes1 ~] # kubectl delete deploy nignx-dp-n kube-publicdeployment.extensions "nignx-dp" deleted- -13. Create a service resource for a nginx-dp pod resource Ensure the high availability of pod Visit [root@test-nodes1 ~] # kubectl get all-n kube-publicNAME READY STATUS RESTARTS AGEpod/nginx-dp-5b9b697bcc-jtrlp 1 Running 0 17sNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/nginx-dp 1 17sNAME via cluster IP DESIRED CURRENT READY AGEreplicaset.apps/nginx-dp-5b9b697bcc 1 1 1 17s [root@test-nodes1 ~] # kubectl get pods-n kube-public-o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx-dp-5b9b697bcc-jtrlp 1 Running 0 3m19s 172.7.21.4 test-nodes1.cedarhd.com [root@test-nodes1 ~] # kubectl expose deployment nginx-dp-- port=80-n kube-publicservice/nginx-dp exposed [root@test-nodes1 ~] # kubectl get svc-n kube-public # View service resource NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEnginx-dp ClusterIP 192.168.224.56 80/TCP 12m [root@test-nodes1 ~] # kubectl get all-n kube-publicNAME READY STATUS RESTARTS AGEpod/nginx-dp-5b9b697bcc-jtrlp 1 Running 0 5m21sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEservice/nginx-dp ClusterIP 192.168.224.56 80/TCP 79sNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/nginx-dp 1 5m21sNAME DESIRED CURRENT READY AGEreplicaset.apps/nginx-dp-5b9b697bcc 1 1 1 5m21s [root@test-nodes1 ~] # curl 192.168.224.56Welcome to nginx! Body {width: 35eme; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.

Thank you for using nginx.

[root@test-nodes1 ~] # ipvsadm-lnIP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 192.168.0.1 443 nq-> 10.3.153.221 lnIP Virtual Server version 6443 Masq 100-> 10.3.153.222 lnIP Virtual Server version 6443 TCP 192 .168.224.56: 80 nq-> 172.7.21.4 nq 80 Masq 1 002. Summary of kubectl declarative management methods: declarative resource management methods depend on-resource allocation list (yaml\ json) Tend to modify the POD configuration.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report