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

Docker port mapping and external inaccessibility issues

The Docker container provides services and listen...

CSS3 overflow property explained

1. Overflow Overflow is overflow (container). Whe...

Using CSS3's 3D effects to create a cube

Learning to use CSS3's 3D effects to create a...

A brief discussion on the performance issues of MySQL paging limit

MySQL paging queries are usually implemented thro...

The benefits and examples of placing the site map at the bottom of the web page

In the past, almost every website had a sitemap p...

Some understanding of absolute and relative positioning of page elements

From today on, I will regularly organize some smal...

Deploy the Vue project on a Linux server

Case 1 vue-cli builds the vue3 project, uploads t...

Split and merge tables in HTML (colspan, rowspan)

The code demonstrates horizontal merging: <!DO...

In-depth understanding of Linux load balancing LVS

Table of contents 1. LVS load balancing 2. Basic ...

VMware installation of Ubuntu 20.04 operating system tutorial diagram

Memo: Just experience it. Record: NO.209 This exa...

How to run JavaScript in Jupyter Notebook

Later, I also added how to use Jupyter Notebook i...

How MySQL supports billions of traffic

Table of contents 1 Master-slave read-write separ...

Detailed explanation of keepAlive usage in Vue front-end development

Table of contents Preface keep-avlive hook functi...

Basic usage and examples of yum (recommended)

yum command Yum (full name Yellow dog Updater, Mo...