How to create a Pod?In the previous article, we introduced the differences and relationships between containers and Pods. We know that Pod is the smallest unit of k8s scheduling, and a Pod can have multiple containers, so how do we define a Pod of our own? In k8s, we usually create a Pod by writing a configuration file. The format of the configuration file is usually yaml (how to represent list and key-value pairs in yaml format is described in the previous article). After writing the yaml file, start a Pod by the following method: kubectl create -f configuration file The definition, parameters, configuration and other information of the container in the Pod are all in the YAML file. A common YAML file content is as follows: apiVersion: v1 kind: Pod metadata: name: volume-pod spec: containers : - name: tomcat image: tomcat ports: - containerPort: 8080 volumeMounts: - name: app-logs mountPath: /usr/local/tomcat/logs - name: busybox image: busybox command: ["sh","-c","tail -f /logs/catalina*.log"] volumeMounts: - name: app-logs mountPath: /logs volumes: - name: app-logs emptyDir: {} Of course, it may have many fields, and you can set the fields yourself depending on the Pod you create. When we submit such a yaml file to k8s, k8s will help us create the corresponding API object. In this example, our object is a Pod (because the value after the kind field in the yaml file is Pod). Of course, there are others. At this point, we have learned how to create a Pod. Regarding the above process, let's look at two more questions: First, what is kubectl? What commands can it follow? Second, what do the fields in the Pod's yaml file mean? Let’s look at the first question first. kubectl toolThe kubectl tool is a client CLI tool that allows users to manage k8s clusters through the command line. The basic syntax of this command is: kubectl 【command】 【type】 【name】 【flags】 command value: get, create, delete, describe, get, apply, etc. type value: the type of resource object, which can be pod, deployment, etc. name value: the name of the resource object, flags: optional parameters, you can view them through --help, eg: kubectl create – Creates resources using a file name or console input. kubectl delete – Delete resources by file name, console input, resource name, or label selector. kubectl annotate – Updates annotations for a resource. kubectl api-versions – Outputs the API versions supported by the server in the format group/version. kubectl apply – Apply configuration to resources using a file name or console input. kubectl attach – Attach to a running container. kubectl autoscale – Automatically scale the replication controller. kubectl cluster-info – Outputs cluster information. kubectl config – Modify the kubeconfig configuration file. kubectl describe – Displays detailed information about the specified resource or resources. kubectl edit – Edit server-side resources. kubectl exec – Executes a command inside a container. kubectl expose – takes a replication controller, service or pod and exposes it as a new Kubernetes service. kubectl get – Outputs one or more resources. kubectl label – Updates a resource’s label. kubectl logs – Outputs the logs for a container in a pod. kubectl namespace - (deprecated) Set or view the currently used namespace. kubectl patch – Updates fields in a resource via console input. kubectl port-forward – Forwards a local port to a Pod. kubectl proxy – starts a proxy server for the Kubernetes API server. kubectl replace – Replaces a resource by filename or console input. kubectl rolling-update – performs a rolling update of the specified replication controller. kubectl run – starts a container using a specified image in the cluster. kubectl scale – Sets the new number of replicas for the replication controller. kubectl stop – (Deprecated) Safely remove a resource by resource name or console input. kubectl version – Outputs server and client version information. Now we know that it is a command line tool. There are so many common operations listed above. You can use the create subcommand to create a Pod. We will discuss other functions in detail each time they are used. Of course, you can use kubectl --help to view its instructions. The above is the details of how to create a Pod in Kubernetes. For more information about creating a Pod in Kubernetes, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
>>: Teach you to use dozens of lines of js to achieve cool canvas interactive effects
The Docker container provides services and listen...
1. Overflow Overflow is overflow (container). Whe...
Learning to use CSS3's 3D effects to create a...
MySQL paging queries are usually implemented thro...
In the past, almost every website had a sitemap p...
From today on, I will regularly organize some smal...
Case 1 vue-cli builds the vue3 project, uploads t...
The code demonstrates horizontal merging: <!DO...
Table of contents 1. LVS load balancing 2. Basic ...
Memo: Just experience it. Record: NO.209 This exa...
Later, I also added how to use Jupyter Notebook i...
Preface Those who have played with MySQL must be ...
Table of contents 1 Master-slave read-write separ...
Table of contents Preface keep-avlive hook functi...
yum command Yum (full name Yellow dog Updater, Mo...