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

How to understand the operation of adding, deleting, changing and searching Pod

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

How to understand the Pod add, delete, change and search operation, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

We use a simple example to demonstrate the operation of adding, deleting, modifying and querying Pod resources.

Create Pod

First save the following configuration to a file named pod_simple.yaml:

ApiVersion: v1kind: Podmetadata: name: pod-runs-nginxspec: containers:-name: nginx image: nginx:latest

As you can see from the configuration, we will create a resource of type Pod. The version of the resource is v1PowerPod, the name of the container is pod-runs-nginx,Pod, the name of the container is nginx, and the container image is nginx:latest.

Use the kubectl create command to create the resource, as follows:

[root@ecs-d8b6] # kubectl create-f pod_simple.yaml pod/pod-runs-nginx created

You can see from the command line output that Kubernetes has created a Pod resource as we configured it.

View Pod

Use the command kubectl get command to view the Pod, as follows:

[root@ecs-d8b6 ~] # kubectl get podsNAME READY STATUS RESTARTS AGEpod-runs-nginx 1amp 1 Running 0 26s

You can see that the Pod named pod-runs-nginx is already in the Running state.

We can also add the-o yaml parameter to the kubectl get command to view more detailed information about Pod, as shown below:

[root@ecs-d8b6] # kubectl get pods pod-runs-nginx-o yamlapiVersion: v1kind: Podmetadata: name: pod-runs-nginx namespace: default uid: 6a946bac-e288-4e19-b743-7ee0eb04aa73... spec: containers:-image: nginx:latest imagePullPolicy: Always name: nginx restartPolicy: Always. Status: phase: Running podIP: 172.17.0.6.

Kubernetes adds a lot of default properties when creating resource objects, which are limited by space, and only part of the information is shown above.

We know that Kubernetes assigns an IP to each Pod, and you can see from the output above that the IP of this Pod is 172.17.0.6, and we can use this IP to access the container in Pod.

Since nginx listens on port 80 by default, we can use Pod IP and port to access nginx, as shown below:

[root@ecs-d8b6 ~] # curl 172.17.0.6:80Welcome to nginxcake.. Welcome to nginx!

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

...

Thank you for using nginx.

From the output, you can see that nginx is working properly.

Update Pod

In the above example, we specified the image version of the container as nginx:latest, and we can change the image version to nginx:1.19.0, so we modify the configuration file as follows:

ApiVersion: v1kind: Podmetadata: name: pod-runs-nginxspec: containers:-name: nginx image: nginx:1.19.0 # modify the image version

Then use the command kubectl apply to submit the modified configuration, as shown below:

[root@ecs-d8b6] # kubectl apply-f pod_simple.yaml pod/pod-runs-nginx configured

Then check the Pod information again, and you can see that the container image version in Pod has been updated:

[root@ecs-d8b6] # kubectl get pods pod-runs-nginx-o yamlapiVersion: v1kind: Podmetadata: name: pod-runs-nginx namespace: default uid: 6a946bac-e288-4e19-b743-7ee0eb04aa73spec: containers:-image: nginx:1.19.0 # Image version has been updated imagePullPolicy: Always name: nginx restartPolicy: Always. Status: phase: Running podIP: 172.17.0.6. Delete Pod

Use the command kubectl delete command to delete the Pod, as follows:

[root@ecs-d8b6 ~] # kubectl delete pods pod-runs-nginx pod "pod-runs-nginx" deleted

Deleting a Pod stops and deletes the containers it contains accordingly.

As the most basic resource, Pod, like other Kubernetes resources, can be operated using kubectl.

After reading the above, have you mastered how to understand the operation of adding, deleting, changing and searching Pod? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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