Tag Archives: K8S error

[Solved] k8s Error: Back-off restarting failed container

1. Cause

When I run Ubuntu through k8s, I execute the following script

#!/bin/bash
service ssh start
echo root:$1|chpasswd

After the container is started, there is no resident foreground process inside the container, which causes the container to exit after the container is started successfully, thus continuing to restart.

2. Solution

At startup, perform a task that will never be completed

command: ["/bin/bash", "-ce", "tail -f /dev/null"]

Add the following to the script above:

#!/bin/bash
service ssh start
echo root:$1|chpasswd
tail -f /dev/null

Successfully solved, this script can be executed successfully, and the container can be started successfully

K8S error validating data: ValidationError(Deployment.spec): missing required field selector

The following error is reported

This is an error when I execute the pod copy of the deployment controller. The meaning of the error is:
deployment verification error. The selector parameter must be specified in the deployment spec module.

Original yaml file

In Deployment.spec In the module, only the number of replicas is specified, and the replica label needs to be specified to match the deployment controller

apiVersion: apps/v1     #Api interface version
kind: Deployment #define controller
metadata:      
 name: nginx-deployment #deployment name
spec:       
 replicas: 3 #Under the specific parameter information spec, only the number of replicas is specified, you also need to specify the replica tag to match the Deployment controller

 template:
   metadata: 
     labels: 
       app: nginx-deployment   
   spec:
     containers:    	
       - name: nginx-deployment  	
         image: nginx:1.7.9  
         ports:   	 
           - containerPort: 80

Solution: modify yaml file

As shown in the figure above, write the selector tag parameters of the full spec according to the tags on the picture, matching with pod and deployment

Execute yaml script

kubectl apply -f deployment.yaml --record