我有一个docker镜像,它是为训练用于对象检测的镜像而创建的。
这是我的图像的dockerfile。
FROM python:3
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY /src/ /Training
WORKDIR /Training
CMD ["/bin/bash"]
要创建我使用的这个容器
sudo docker image build -t training .
此图像的容器运行良好,我可以在计算机上进行训练。
我使用
将该图像推送到我的私有docker hub存储库中docker tag training abhishekkaranath/training:training
docker push abhishekkaranath/training:training
training image in my private docker hub repository
我使用以下方法为我的部署文件创建了一个秘密
kubectl create secret docker-registry hubsecret --docker-server=https://index.docker.io/v1/ --docker-username=my_username --docker-password=my_docker_hub_password --docker-email=my_email
下面是我的deployment.yaml文件
apiVersion: v1
kind: Pod
metadata:
name: podtest
spec:
containers:
- name: podtest
image: abhishekkaranath/training:training
imagePullSecrets:
- name: hubsecret
我使用以下方法在终端上创建了这个广告连播
kubectl create -f deployment.yaml
结果如下:
pod/podtest created
在检查我的minikube仪表板时,出现错误消息:“退回重新启动失败的容器”。
Back off restarting failed container
我尝试将hello world映像从我的私有docker hub存储库中拉入kubernetes,它工作正常,并且pod已启动并正在运行。因此,这意味着从私有docker hub存储库中提取图像没有问题。
kubectl get pods
NAME READY STATUS RESTARTS AGE
podtest 0/1 CrashLoopBackOff 8 20m
kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready master 11d v1.14.2
kubectl describe pods podtest
Name: podtest
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: minikube/10.0.2.15
Start Time: Thu, 06 Jun 2019 18:33:02 +0400
Labels: <none>
Annotations: <none>
Status: Running
IP: 172.17.0.9
Containers:
podtest:
Container ID: docker://14b9fcc51c8b4a594e0b38580444e2fedd61a636f4e57374d788c9ba5bf9fbcf
Image: abhishekkaranath/training:training
Image ID: docker-pullable://abhishekkaranath/training@sha256:619468dd0b74b30babfd7c0702c21ea71e9fb70ba3971ec26e8279fdbd071ec7
Port: <none>
Host Port: <none>
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Completed
Exit Code: 0
Started: Thu, 06 Jun 2019 18:54:19 +0400
Finished: Thu, 06 Jun 2019 18:54:19 +0400
Ready: False
Restart Count: 9
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-lb9js (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-lb9js:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-lb9js
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 25m default-scheduler Successfully assigned default/podtest to minikube
Normal Pulled 23m (x5 over 25m) kubelet, minikube Container image "abhishekkaranath/training:training" already present on machine
Normal Created 23m (x5 over 25m) kubelet, minikube Created container podtest
Normal Started 23m (x5 over 25m) kubelet, minikube Started container podtest
Warning BackOff 4m51s (x94 over 24m) kubelet, minikube Back-off restarting failed container
kubectl --v=8 logs podtest
I0606 19:03:24.821394 3978 loader.go:359] Config loaded from file /home/abhishekkaranath/.kube/config
I0606 19:03:24.826732 3978 round_trippers.go:416] GET https://192.168.99.100:8443/api/v1/namespaces/default/pods/podtest
I0606 19:03:24.826748 3978 round_trippers.go:423] Request Headers:
I0606 19:03:24.826757 3978 round_trippers.go:426] Accept: application/json, */*
I0606 19:03:24.826764 3978 round_trippers.go:426] User-Agent: kubectl/v1.14.1 (linux/amd64) kubernetes/b739410
I0606 19:03:24.835800 3978 round_trippers.go:441] Response Status: 200 OK in 9 milliseconds
I0606 19:03:24.835818 3978 round_trippers.go:444] Response Headers:
I0606 19:03:24.835827 3978 round_trippers.go:447] Content-Length: 2693
I0606 19:03:24.835834 3978 round_trippers.go:447] Date: Thu, 06 Jun 2019 15:03:24 GMT
I0606 19:03:24.835840 3978 round_trippers.go:447] Content-Type: application/json
I0606 19:03:24.835870 3978 request.go:942] Response Body: {"kind":"Pod","apiVersion":"v1","metadata":{"name":"podtest","namespace":"default","selfLink":"/api/v1/namespaces/default/pods/podtest","uid":"fd87b14c-8867-11e9-a507-0800276a11ac","resourceVersion":"415630","creationTimestamp":"2019-06-06T14:33:02Z"},"spec":{"volumes":[{"name":"default-token-lb9js","secret":{"secretName":"default-token-lb9js","defaultMode":420}}],"containers":[{"name":"podtest","image":"abhishekkaranath/training:training","resources":{},"volumeMounts":[{"name":"default-token-lb9js","readOnly":true,"mountPath":"/var/run/secrets/kubernetes.io/serviceaccount"}],"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","serviceAccountName":"default","serviceAccount":"default","nodeName":"minikube","securityContext":{},"imagePullSecrets":[{"name":"hubsecret"}],"schedulerName":"default-scheduler","tolerations":[{"key":"node.kubernetes.io/not-ready","oper [truncated 1669 chars]
I0606 19:03:24.840211 3978 round_trippers.go:416] GET https://192.168.99.100:8443/api/v1/namespaces/default/pods/podtest/log
I0606 19:03:24.840227 3978 round_trippers.go:423] Request Headers:
I0606 19:03:24.840235 3978 round_trippers.go:426] Accept: application/json, */*
I0606 19:03:24.840241 3978 round_trippers.go:426] User-Agent: kubectl/v1.14.1 (linux/amd64) kubernetes/b739410
I0606 19:03:24.843633 3978 round_trippers.go:441] Response Status: 200 OK in 3 milliseconds
I0606 19:03:24.843657 3978 round_trippers.go:444] Response Headers:
I0606 19:03:24.843666 3978 round_trippers.go:447] Date: Thu, 06 Jun 2019 15:03:24 GMT
I0606 19:03:24.843673 3978 round_trippers.go:447] Content-Type: text/plain
kubectl get events
LAST SEEN TYPE REASON OBJECT MESSAGE
37m Warning BackOff pod/dhubservice Back-off restarting failed container
31m Normal Scheduled pod/podtest Successfully assigned default/podtest to minikube
29m Normal Pulled pod/podtest Container image "abhishekkaranath/training:training" already present on machine
29m Normal Created pod/podtest Created container podtest
29m Normal Started pod/podtest Started container podtest
69s Warning BackOff pod/podtest Back-off restarting failed container
docker pull abhishekkaranath/training:training
training: Pulling from abhishekkaranath/training
Digest: sha256:619468dd0b74b30babfd7c0702c21ea71e9fb70ba3971ec26e8279fdbd071ec7
Status: Image is up to date for abhishekkaranath/training:training
答案 0 :(得分:1)
@Mark 是正确的。 CrashLoopBackOff 的原因是创建了容器,它根据 dockerfile 中的 CMD 运行 /bin/bash 并退出。
如果你想让容器继续运行,你应该使用以下命令执行你的python代码:
CMD ["python", "-m", "<module_name>"]
要记住的另一件事是,一旦您的应用停止,容器就会退出。因此,如果应用程序是一个虚拟代码,请确保在无限循环中运行它以保持容器和应用程序运行。
答案 1 :(得分:0)
调查:
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Completed
Exit Code: 0
Started: Thu, 06 Jun 2019 18:54:19 +0400
Finished: Thu, 06 Jun 2019 18:54:19 +0400
Ready: False
Restart Count: 9
您的广告连播已排定,容器已创建并完成工作。 根据文档Pod Lifecycle。