Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

State Analysis of K8S Pod status

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

State Analysis of K8S Pod status CrashLoopBackOff: container exit Kubelet is restarting it InvalidImageName: unable to resolve image name ImageInspectError: unable to verify image ErrImageNeverPull: policy forbids pulling image ImagePullBackOff: pulling RegistryUnavailable: unable to connect to image center ErrImagePull: general error pulling image CreateContainerConfigError: cannot create container configuration used by kubelet CreateContainerError: create container failed m.internalLifecycle.PreStartContainer execute hook error RunContainerError: start container failed PostStartHookError: execute hook Error ContainersNotInitialized: container is not initialized ContainersNotReady: container is not ready ContainerCreating: container creation PodInitializing:pod initialization DockerDaemonNotReady:docker is not fully started NetworkPluginNotReady: network plug-in is not fully started yet

Use and commands of K8S-YAML

YAML profile management object management: # create deployment resources kubectl create-f nginx-deployment.yaml# view deploymentkubectl get deploy# view ReplicaSetkubectl get rs# view pods all tags kubectl get pods-- show-labels# view podskubectl get pods-l app=nginx# scroll update image kubectl set image deployment/nginx-deployment nginx=nginx:1.11 or kubectl edit deployment/nginx-deployment or kubectl apply-f nginx-deployment.yaml# real-time Observe the release status: kubectl rollout status deployment/nginx-deployment# to view the historical revision of deployment kubectl rollout history deployment/nginx-deploymentkubectl rollout history deployment/nginx-deployment-- revision=3# rollback to the previous version kubectl rollout undo deployment/nginx-deploymentkubectl rollout undo deployment/nginx-deployment-- number of Pod copies of to-revision=3# expansion deployment kubectl scale deployment nginx-deployment-- replicas=10# setting to start capacity expansion / reduction kubectl autoscale deployment nginx-deployment-- min=10-- max=15-- cpu-percent=80

Object management example: vim nginx.deployment.yaml

ApiVersion: apps/v1beta2kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers:-name: nginx image: nginx:1.10 ports:-containerPort: 80

Service Discovery example: vim nging.service.yaml

ApiVersion: v1kind: Servicemetadata: labels: run: nginx name: nginx namespace: defaultspec: ports:-port: 88 targetPort: 80 selector: app: nginx

Clean up:

# kubectl delete-f nginx-deployment.yaml

# kubectl delete-f nginx-service.yaml

POD function:

Pod management-create / query / update / delete basic management: # create pod resource kubectl create-f pod.yaml# view podskubectl get pods pod-test# view pod description kubectl describe pod pod-test# replacement resource kubectl replace-f pod.yaml-force# delete resource kubectl delete pod pod-test

Three strategies are supported:

Always: always restart the container when it terminates and exits. The default policy is.

OnFailure: restart the container only when the container exits abnormally (the exit status code is not 0).

Never: never restart the container when it terminates and exits.

Pod instance: vim pod.yaml

ApiVersion: v1kind: Podmetadata: name: pod-test labels: os: centosspec: containers:-name: hello image: centos:7 env:-name: Test value: "123456" command: ["bash", "- c", "while true;do date;sleep 1 done"] restartPolicy: OnFailure

Pod Management-Health check:

There are two types of Probe mechanism: if livenessProbe fails to check, it will kill the container, and then decide whether to restart it according to the restart policy of Pod. If the readinessProbe fails, Kubernetes removes the Pod from the distribution backend of the service agent. Probe supports the following three check methods: httpGet sends a HTTP request and returns a status code in the range of 200-400 as successful. Exec executes the Shell command and returns a status code of 0 as successful. TcpSocket initiated TCP Socket to establish successfully.

Example: vim pod2.yaml

ApiVersion: v1kind: Podmetadata: name: nginx-pod labels: app: nginxspec: containers:-name: nginx image: nginx:1.10 ports:-containerPort: 80 livenessProbe: httpGet: path: / index.html port: 80

Pod Management-data persistence and sharing:

Vim pod3.yaml

ApiVersion: v1kind: Podmetadata: name: pod-test1 labels: test: centosspec: containers: # first container-name: hello-write image: centos:7 command: ["bash", "- c", "for i in {1.. 1000}; do echo $I > > / data/hello;sleep 1 done"] # second container-name: hello-read image: centos:7 command: ["bash", "- c", "for i in {1... 1000}" Do cat $I > > / data/hello;sleep 1 done "] volumeMounts:-name: data mountPath: / data # data volume volumes:-name: data hostPath: path: / data

Pod Port Mapping:

Vim pod4.yaml

ApiVersion: v1kind: Podmetadata: name: nginx-pod labels: app: nginxspec: containers:-name: nginx image: nginx:1.10 ports:-name: http containerPort: 80 hostIP: 0.0.0.0 hostPort: 80 protocol: TCP-name: https containerPort: 443hostIP: 0.0.0.0 hostPort: 443protocol: TCP

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report