Kubernetes Detailed Explanation (6) - Pod Object Deployment and Application

Today, I will continue to introduce the relevant knowledge of Linux operation and maintenance. The main content of this article is the deployment and application of Pod objects.
In the previous Kubernetes detailed explanation (4) - Kubernetes deployment based on kubeadm , we introduced the installation and deployment of Kubernetes clusters. Next, we will use the Kubernetes cluster to create, view, access and delete Pod objects.

1. Pod resource creation

The format of the command to create a Pod resource object is:

kubectl run 【Pod名】 --image=【Pod使用的镜像名】 --port=【Pod对象运行的端口】 --replicas=【创建的Pod对象的副本数】

For example, execute the command:

kubectl run pod-test --image=nginx:1.12 --port=80 --replicas=1

You can open an image, and the execution result is as follows:
insert image description here
In this way, the Pod object is created successfully!

2. View Pod resources

After the Pod resource object is successfully created, we execute the command:

kubectl get deployment

or

kubectl get pods

You can view the information of the Pod. The execution results of these two commands are as follows:
insert image description here
insert image description here
On the basis of these two commands, add the -o wide parameter to view the detailed information of the Pod object. The commands are as follows:

kubectl get deployment -o wide
kubectl get pods -o wide

The execution results of these two commands are as follows:
insert image description here
insert image description here
In the results of the above command execution, NAME is the name of the Pod object, the name prefix is ​​the name we specified when creating the Pod object, followed by a random number; READY is the number of ready , the number before the slash is the number of ready containers, and the number after the slash is the total number of containers in the Pod container; STATUS indicates the running status of the container; RESTART indicates the number of restarts of the container; AGE indicates the container's Running time; IP indicates the IP address of the container; NODE indicates the node where the Pod is located; IMAGES indicates the image used by the Pod; SELECTION indicates the label of the Pod;

3. Pod resource access

After the Pod resource is created, we can access the Pod resource. When we view the Pod object, we can see the IP address of the Pod resource.
We can use curl to access the Pod resources, and the access results are as follows:
insert image description here
Note:
In the Kubernetes cluster, although the Pod runs on Node2, the Pod can be accessed on any node.

Fourth, Pod node deletion

If we want to delete a Pod node, the command format is:

kubectl delete pods 【Pod名】

The execution result of this command is as follows:
insert image description here
Note that in the Kubernetes cluster, since the Pod is controlled by the Controller controller, although we can delete the Pod object, the Controller controller will create the Pod object again.
Originality is not easy, please indicate the source for reprinting: https://blog.csdn.net/weixin_40228200

Guess you like

Origin blog.csdn.net/weixin_40228200/article/details/124284402