Kubernetes

k8s启动nginx容器错误CrashLoopBackOff

本文主要是介绍k8s启动nginx容器错误CrashLoopBackOff,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

这里主要是因为是自己做的一个的一个nginx镜像(这里就不重复了)

~]# kubectl apply -f mynginx.yaml 
daemonset.apps/mynginx created

CrashLoopBackoff

~]# kubectl get pods -o wide
NAME            READY   STATUS             RESTARTS      AGE     IP            NODE              NOMINATED NODE   READINESS GATES
mynginx-2qcvt   0/1     CrashLoopBackOff   5 (94s ago)   4m24s   10.244.1.24   vm-0-114-centos   <none>           <none>
mynginx-drpq9   0/1     CrashLoopBackOff   5 (85s ago)   4m24s   10.244.2.32   vm-0-142-centos   <none>           <none>
# 查看报错
~]# kubectl describe pods -n default mynginx-2qcvt 

.......

Warning  BackOff    38s (x9 over 2m21s)  kubelet            Back-off restarting failed container

~]# kubectl logs -n default mynginx-2qcvt

# 此时发现没有有用的报错
# 随便找一台节点的容器是否启动,

~]# docker ps -a
CONTAINER ID   IMAGE                                            COMMAND                  CREATED              STATUS                          PORTS     NAMES
53d55b422a04   f276e0f4fb5b                                     "/bin/bash"              About a minute ago   Exited (0) About a minute ago             k8s_nginxcluster_mynginx-2qcvt_default_f1552f7b-85f2-42cb-9425-d5e4ae851075_6

# 这里发现是我的容器启动失败了,然后尝试手动启动
~]# docker start 53d55b422a04
~]# docker ps -a
CONTAINER ID   IMAGE                                            COMMAND                  CREATED              STATUS                          PORTS     NAMES
53d55b422a04   f276e0f4fb5b                                     "/bin/bash"              About a minute ago   Exited (0) About a minute ago             k8s_nginxcluster_mynginx-2qcvt_default_f1552f7b-85f2-42cb-9425-d5e4ae851075_6 
# 发现还是没起来,这里突然想到nginx的启动会杀死他爹的,也就是system上帝京进程,然后我的yaml文件没有写启动命令,也就是默认启动,自然是失败的,所以这里再yaml文件中修改一下

~]# vim mynginx.yaml
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
   name: mynginx
spec:
   selector:
      matchLabels:
         myapp: nginx
   template:
      metadata:
        labels:
           myapp: nginx
      spec:
        containers:
        - name: nginxcluster
          image: 172.17.0.98:5000/myos:nginx2
          command: ["/data/nginx/sbin/nginx", "-g", "daemon off;"]   # 增加一个启动命令
          stdin: false
          tty: false
          ports:
          - protocol: TCP
            containerPort: 80
        restartPolicy: Always

~]# kubectl apply -f mynginx.yaml                             
daemonset.apps/mynginx configured

~]# kubectl get pods -o wide
NAME            READY   STATUS    RESTARTS   AGE   IP            NODE              NOMINATED NODE   READINESS GATES
mynginx-4qwl8   1/1     Running   0          3s    10.244.2.34   vm-0-142-centos   <none>           <none>
mynginx-tzs48   1/1     Running   0          3s    10.244.1.26   vm-0-114-centos   <none>           <none>

# 此时问题解决

这篇关于k8s启动nginx容器错误CrashLoopBackOff的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!