Today, I will continue to introduce the relevant knowledge of Linux operation and maintenance. The main content of this article is to create a Pod through the resource configuration list.
1. Compilation of resource allocation list
In the above Kubernetes detailed explanation (8) - Kubernetes resource configuration list , we introduced the common fields of Kubernetes resource configuration list. Today, we will use the resource configuration list to actually generate a Pod object to show the Kubernetes resource configuration list. effect.
First, we create a resource configuration manifest file pod-demo-test.yaml and write the following content:
apiVersion: v1
kind: Pod
metadata:
name: pod-demo-test
namespace: default
labels:
label1: mypod1
label2: mypod2
spec:
containers:
- name: container
image: ikubernetes/myapp:v1
- name: busybox
image: busybox
command:
- "/bin/bash"
- "-c"
- "sleep 7200"
In this resource list, we define a Pod object, the previous content is basically fixed, and it has been introduced in Kubernetes Detailed Explanation (8) - Kubernetes Resource Configuration List . Under the spec field, we mainly have the field of containers, which defines the container in the Pod resource, the name field defines the name of the container; the image field defines the image of the container; the command field defines the command executed after the container runs . It can be seen that in the Pod resource object, we define two containers, one is myapp and the other is busybox.
After the resource object is configured, it looks like this:
Second, the resource configuration list to create a Pod
After the resource list is completed, we can create a Pod resource object based on the resource list.
Excuting an order:
kubectl create -f pod-demo.test.yaml
This allows Kubernetes to create a Pod object according to the configuration of our resource list. In the above command, the -f parameter specifies a file followed by the file name.
Note: We are using the YAML format here. The YAML format is very strict with spaces and indentation, so we have to pay special attention!
The execution result of the command is as follows:
After the command is executed, we can view the Pod object and execute the command:
kubectl describe pods pod-demo-test
The execution result of this command is as follows:
3. Description of the Command relationship in the mirror and Pod
Finally, let's talk about the relationship between the following image and the Command command in the Pod.
In the resource configuration list, we configure the command command under the image, but in fact, under the Pod resource list, we can also configure CMD (similar to Command). And in the image and Pod we can also configure the args variable (ENTRYPOINT in the image). The command command and args parameter configuration relationship between the image and the Pod is as follows:
1. If the Command and args are not configured in the Pod, use the CMD and ENTRYPOINT in the image
2. If the Command is set in the Pod, but there is no args, use the Pod Command in , ignore CMD and ENTRYPOINT in the mirror
3. If only args are set in the Pod, args will be used as parameters for ENTRYPOINT in the mirror.
4. If Command and args are set in both the Pod and the image, the CMD and ENTRYPINT in the image will be ignored, and the Command and args in the Pod will be used.
Originality is not easy, please indicate the source for reprinting: https://blog.csdn.net/weixin_40228200