In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
What this article shares with you is about how to operate ReplicationController. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
We use some examples to demonstrate the creation, view, update, delete and other operations of ReplicationController.
Create
First, we prepare a configuration file called replication_controller_simple.yaml, which is as follows:
[root@ecs-d8b6 manifests] # cat replication_controller_simple.yaml apiVersion: v1kind: ReplicationControllermetadata: name: replication-controller-runs-podspec: replicas: 3 selector: app: nginx template: metadata: labels: app: nginx spec: containers:-name: nginx image: nginx:1.19.0
This ReplicationController configuration ensures that there are three copies of Pod running at the same time.
Use the kubectl create command to create the resource, as follows:
[root@ecs-d8b6 manifests] # kubectl create-f replication_controller_simple.yaml replicationcontroller/replication-controller-runs-pod created View
Let's first take a look at the ReplicationController resource we just created:
[root@ecs-d8b6 manifests] # kubectl get replicationcontrollers NAME DESIRED CURRENT READY AGEreplication-controller-runs-pod 3 3 3 3m4s
You can see that the expected number of Pod (DESIRED) is 3, the number of Pod currently created (CURRENT) is 3, and the number of Pod in the running state (READY) is also 3, which is exactly what we expect.
Next, let's take a look at the actual running Pod:
[root@ecs-d8b6 manifests] # kubectl get podsNAME READY STATUS RESTARTS AGEreplication-controller-runs-pod-gv4l6 1/1 Running 0 6m11sreplication-controller-runs-pod-pcpmb 1/1 Running 0 6m11sreplication-controller-runs-pod-qxrhz 1/1 Running 0 6m11s
You can see that Pod is also running normally.
Finally, let's look at the details of ReplicationController:
[root@ecs-d8b6 manifests] # kubectl describe replicationcontrollers replication-controller-runs-podName: replication-controller-runs-podNamespace: defaultSelector: app=nginxLabels: app=nginxAnnotations: Replicas: 3 current / 3 desiredPods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 FailedPod Template: Labels: app=nginx Containers: nginx: Image: nginx:1.19.0 Port: Host Port: Environment: Mounts: Volumes: Events: Type Reason Age From Message-Normal SuccessfulCreate 10m replication-controller Created pod: replication-controller-runs-pod-gv4l6 Normal SuccessfulCreate 10m replication-controller Created pod: replication-controller-runs-pod-qxrhz Normal SuccessfulCreate 10m replication-controller Created pod: replication-controller-runs-pod-pcpmb
As you can see from the Events information in the last section, the Pod shown above was indeed created by a ReplicationController named replication-controller-runs-pod.
Update to change the number of copies
Let's change the number of copies in the above replication_controller_simple.yaml configuration file from 3 to 5, and then use kubectl apply to commit the changes:
[root@ecs-d8b6 manifests] # kubectl apply-f replication_controller_simple.yaml replicationcontroller/replication-controller-runs-pod configured
Then look at the Pod again, and you can see that the number of Pod will be adjusted to 5 accordingly.
[root@ecs-d8b6 manifests] # kubectl get podsNAME READY STATUS RESTARTS AGEreplication-controller-runs-pod-gv4l6 1/1 Running 0 25mreplication-controller-runs-pod-pcpmb 1/1 Running 0 25mreplication-controller-runs-pod-qtd4b 1/1 Running 0 6sreplication-controller-runs-pod-qxrhz 1/1 Running 0 25mreplication-controller-runs-pod-zz6fj 1/1 Running 0 6s
Similarly, when the number of copies becomes smaller, the extra Pod will be deleted.
Simulate Pod exception
Assuming that the number of Pod copies maintained by the current ReplicationController named replication-controller-runs-pod is 3, we simulate the Pod exception by deleting the Pod, as shown below:
[root@ecs-d8b6 manifests] # kubectl get podsNAME READY STATUS RESTARTS AGEreplication-controller-runs-pod-gv4l6 1/1 Running 0 30mreplication-controller-runs-pod-pcpmb 1/1 Running 0 30mreplication-controller-runs-pod-qxrhz 1/1 Running 0 30m [root@ecs-d8b6 manifests] # [root@ecs-d8b6 manifests] # [root@ecs-d8b6 manifests] # [root@ecs-d8b6 manifests] # kubectl delete pods replication-controller-runs-pod-gv4l6 pod "replication-controller-runs-pod-gv4l6" deleted [root@ecs-d8b6 manifests] # kubectl get podsNAME READY STATUS RESTARTS AGEreplication-controller-runs-pod-4598b 1 Running 0 10sreplication-controller-runs-pod-pcpmb 1 Running 0 31mreplication-controller-runs-pod-qxrhz 1/1 Running 0 31m
As you can see, when we delete the Pod named replication-controller-runs-pod-gv4l6, a new Pod object, replication-controller-runs-pod-4598b, is created immediately, ensuring that the number of copies remains the same.
Delete
When you delete a ReplicationController object, the Pod created by that object is also deleted by default, as follows:
[root@ecs-d8b6 manifests] # kubectl delete-f replication_controller_simple.yaml replicationcontroller "replication-controller-runs-pod" deleted [root@ecs-d8b6 manifests] # kubectl get podsNAME READY STATUS RESTARTS AGEreplication-controller-runs-pod-ktrxr 0Universe 1 Terminating 0 18sreplication-controller-runs-pod-rcdhk 0pod- Sc9mj 0/1 Terminating 0 18s [root@ecs-d8b6 manifests] # kubectl get podsNo resources found in default namespace. The above is how to operate ReplicationController, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.