How to create a Pod in Kubernetes

How to create a Pod in Kubernetes

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 tool

The 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:
  • Detailed explanation of the use of cloud native technology kubernetes scheduling unit pod
  • Detailed explanation of the use of cloud native technology kubernetes scheduling unit pod
  • Introduction to cloud native technology kubernetes (K8S)
  • Detailed explanation of Kubernetes pod orchestration and lifecycle
  • kubernetes k8s Getting Started Define a Pod

<<:  Web Design Experience

>>:  Teach you to use dozens of lines of js to achieve cool canvas interactive effects

Recommend

Try Docker+Nginx to deploy single page application method

From development to deployment, do it yourself Wh...

Detailed explanation of Vue3.0 + TypeScript + Vite first experience

Table of contents Project Creation Project Struct...

Solution for forgetting the root password of MySQL5.7 under Windows 8.1

【background】 I encountered a very embarrassing th...

About MariaDB database in Linux

Table of contents About MariaDB database in Linux...

JavaScript to implement login slider verification

This article example shares the specific code of ...

Detailed explanation of putting common nginx commands into shell scripts

1. Create a folder to store nginx shell scripts /...

Design theory: Why are we looking in the wrong place?

I took the bus to work a few days ago. Based on m...

Vue implements calling PC camera to take photos in real time

Vue calls the PC camera to take pictures in real ...

Detailed explanation of Tomcat's Server Options

1. Configuration By default, the first two are no...

How to get the current time using time(NULL) function and localtime() in Linux

time(); function Function prototype: time_t time(...

Top 10 useful and important open source tools in 2019

In Black Duck's 2017 open source survey, 77% ...