我正在阅读Vyas和Love的Core Kubernetes。这是第141页7. 3节的YAML文件。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dynamic1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100k
---
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- image: busybox
name: busybox
volumeMounts:
- mountPath: /shared
name: shared
- image: nginx
imagePullPolicy: Always
name: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- mountPath: /var/www
name: dynamic1
- mountPath: /shared
name: shared
volumes:
- name: dynamic1
persistentVolumeClaim:
claimName: dynamic1
- name: shared
emptyDir: {}
我在此文件上运行kubectl create
,然后运行kubectl get pods --all-namespaces
。它显示nginx
pod的状态为CrashLoopBackOff
。使用kubectl describe pods nginx
显示:
Warning FailedScheduling 105s default-scheduler 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.
Normal Scheduled 104s default-scheduler Successfully assigned default/nginx to minikube
Normal Pulling 101s kubelet Pulling image "nginx"
Normal Pulled 101s kubelet Successfully pulled image "busybox" in 2.289652482s
Normal Pulled 99s kubelet Successfully pulled image "nginx" in 2.219896558s
Normal Created 98s kubelet Created container nginx
Normal Started 98s kubelet Started container nginx
Normal Pulled 96s kubelet Successfully pulled image "busybox" in 2.23260066s
Normal Pulled 78s kubelet Successfully pulled image "busybox" in 2.245476487s
Normal Pulling 49s (x4 over 103s) kubelet Pulling image "busybox"
Normal Created 47s (x4 over 101s) kubelet Created container busybox
Normal Pulled 47s kubelet Successfully pulled image "busybox" in 2.287877562s
Warning BackOff 46s (x5 over 95s) kubelet Back-off restarting failed container
Normal Started 46s (x4 over 101s) kubelet Started container busybox
运行kubectl logs nginx nginx
显示:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/12/08 14:37:51 [notice] 1#1: using the "epoll" event method
2022/12/08 14:37:51 [notice] 1#1: nginx/1.23.2
2022/12/08 14:37:51 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/12/08 14:37:51 [notice] 1#1: OS: Linux 5.15.0-56-generic
2022/12/08 14:37:51 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/12/08 14:37:51 [notice] 1#1: start worker processes
2022/12/08 14:37:51 [notice] 1#1: start worker process 30
2022/12/08 14:37:51 [notice] 1#1: start worker process 31
2022/12/08 14:37:51 [notice] 1#1: start worker process 32
2022/12/08 14:37:51 [notice] 1#1: start worker process 33
2022/12/08 14:37:51 [notice] 1#1: start worker process 34
2022/12/08 14:37:51 [notice] 1#1: start worker process 35
2022/12/08 14:37:51 [notice] 1#1: start worker process 36
2022/12/08 14:37:51 [notice] 1#1: start worker process 37
运行kubectl logs nginx busybox
没有显示任何内容。然后我注解掉nginx
pod中的busybox
容器,它工作正常。当我注解掉nginx
pod中的'nginx'容器时,它再次遇到错误。我想知道为什么这个容器会导致这个问题?任何见解都是非常感谢的。
附录:
运行kubectl get sc
显示:
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
standard (default) k8s.io/minikube-hostpath Delete Immediate false 35h
运行kubectl get event
显示:
LAST SEEN TYPE REASON OBJECT MESSAGE
2m12s Warning BackOff pod/nginx Back-off restarting failed container
1条答案
按热度按时间bvjveswy1#
搜索一下,我找到了这个busybox.yaml文件,其中包含
sleep
命令。我将其添加到busybox
容器中,如下所示:现在yaml文件工作了。我猜这和Sreepada Jayanthi的答案有关。这个Reddit post也解释了细节。