“This is the 24th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
In K8S, POD is a very key existence. Let’s see what pod is specifically.
What is pod?
What is a pod? Pod is a core concept in K8S
Each POD has a special root container called pause, and the pause image is also part of K8S
A POD can contain more than just pause containers
Each POD is an instance of a specific application. A POD has its own IP, hostname, process, and so on
- Pod has a one-to-many relationship with the container
A POD can have multiple containers that share network and storage resources with each other
We manage our other containers through the Pause container in pod, because the Pause container stores all container states
- Pod and node relationship
Pods exist in nodes. Pods of different nodes communicate with each other through layer 2 networks
- What’s different about pod itself?
Pods themselves are also divided into regular pods and static pods
How do we define a POD
Defining a POD in K8S is also relatively easy, just write a YAML file, but it takes a bit of trial and practice to get started
A YAML file looks like this, written by hand. I’ll explain some of the terms that are not easy to understand or misunderstood
apiVersion: v1 // The version number
kind: Pod // type
metadata:
name: pod name
namespace: pod namespace
labels:
- name: pod label
annotations:
- name: pod annotation // Custom comment list
spec: // pod A detailed definition of a container in
container:
- name: container name
image: container image
imagesPullPolicy: [Always|Never|IfNotPresent] // Mirror pull policy
command: command list
agrs: app start params
workingDir: work dir
volumeMounts:
- name: volume name
mountPath: volume absolutely path
readonly: boolean
ports:
- name: ports list name
containerPort: 8888
hostPort: 9999
protocol: TCP // Can be TCP and UDP
env:
- name: env name
value: string
resources:
limits:
cpu: string
memory: string
requeste:
cpu: string
memory: string
livenessProbe: // Health Check Settings
exec:
command: [string]
httpGet: // through httpGet Way to check
path: string
port: string
host: string
scheme: string
httpHeaders:
- name: httpHeaders name
value: string
tcpSocket: // through tcpSocket Way to check
port: 80
initialDelaySeconds: 0 // Time of first inspection
timeoutSeconds: 0 // Timeout check time
periodSeconds: 0 // Check interval
successTreshold: 0
failuerTreshold: 0
securityContext: // Security configuration
privileged: false
restartPolicy: [Always|Never|OnFailure]
nodeSelector: object
imagePullSecrets:
- name: string
hostNetwork: false // Is the host network mode used?
volumes: // Storage volume
- name: volumes list name
emptyDir: {}
hostPath: // pod Directory of the host for mounting
path: string
secret: // secret type Storage volume
secretName: secret name
item:
- key: specific key
path: key path
configMap: // configmap Type storage volume
name: string
items:
- key: specific key
path: string
Copy the code
See the above yamL, at first may feel a little too much, I can not remember, XDM, did not let you remember, we just need to know the POD yamL looks like this, which are used
Pod Basic Usage Example
There are also requirements in K8S for container operation in POD
- The container’s main program runs in the foreground, not in the background, so the application needs to be retrofitted to run in the foreground
- If the container contained in the POD is a daemon, the pod will be destroyed after the command is executed
- If pod is rc, rc is replicationController, then pod will be in a create/destroy cycle
We share the pod, which can be one container or multiple containers, according to our needs
One POD for one container
For example, a container with a mongdb inside a pod can be written like this
A POD holds multiple containers
For example, if we put 1 mongodb and 1 Redis container in 1 pod, we can write it like this
How to operate pod
Create pods based on existing YAML
Kubectl create -f yaml fileCopy the code
View pods and view pod details
Something like this
- kubectl get pod -A
View pods under all namespaces
- Kubectl get pod name
- Kubectl get pod pod name -o wide
Check out pod for more information
- Kubectl describe pod name
View pod details
Delete the pod
- Kubectl delete pod Pod name
- Kubectl delete pod Pod name -n namespace
kubectl delete pod --all
Delete all pods
Today is here, learning, if there is a deviation, please correct
Welcome to like, follow and favorites
Friends, your support and encouragement, I insist on sharing, improve the quality of the power
All right, that’s it for this time
Technology is open, our mentality, should be more open. Embrace change, live in the sun, and strive to move forward.
I am Nezha, welcome to like, see you next time ~