在Azure AKS中退后重新启动失败的容器

时间:2020-06-12 12:42:14

标签: kubernetes azure-aks linux-containers

具有来自Azure Container注册表的docker映像的Linux容器pod始终使用restartPolicy始终重新启动。广告连播说明如下。

kubectl describe pod example-pod

...

State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 11 Jun 2020 03:27:11 +0000
      Finished:     Thu, 11 Jun 2020 03:27:12 +0000
...
Back-off restarting failed container

此Pod是秘密创建的,可以访问ACR注册表存储库。 原因是pod使用退出代码0成功完成了执行。但是,它应该继续侦听特定的端口号。 Microsoft文档链接位于标题“容器不断退出并重新启动”下的该URL Container Group Runtime

deployment-example.yml 文件内容如下。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deployment
  namespace: development
  labels:
    app: example
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: example
        image: contentocr.azurecr.io/example:latest
        #command: ["ping -t localhost"]
        imagePullPolicy: Always
        ports:
        - name: http-port
          containerPort: 3000
      imagePullSecrets:
        - name: regpass
      restartPolicy: Always
      nodeSelector:
        agent: linux
---
apiVersion: v1
kind: Service
metadata:
  name: example
  namespace: development
  labels:
    app: example
spec:
  ports:
  - name: http-port
    port: 3000
    targetPort: 3000
  selector:
      app: example
  type: LoadBalancer

kubectl get events 的输出如下。

3m39s       Normal    Scheduled              pod/example-deployment-5dc964fcf8-gbm5t    Successfully assigned development/example-deployment-5dc964fcf8-gbm5t to aks-agentpool-18342716-vmss000000
2m6s        Normal    Pulling                pod/example-deployment-5dc964fcf8-gbm5t    Pulling image "contentocr.azurecr.io/example:latest"
2m5s        Normal    Pulled                 pod/example-deployment-5dc964fcf8-gbm5t    Successfully pulled image "contentocr.azurecr.io/example:latest"
2m5s        Normal    Created                pod/example-deployment-5dc964fcf8-gbm5t    Created container example
2m49s       Normal    Started                pod/example-deployment-5dc964fcf8-gbm5t    Started container example
2m20s       Warning   BackOff                pod/example-deployment-5dc964fcf8-gbm5t    Back-off restarting failed container
6m6s        Normal    SuccessfulCreate       replicaset/example-deployment-5dc964fcf8   Created pod: example-deployment-5dc964fcf8-2fdt5
3m39s       Normal    SuccessfulCreate       replicaset/example-deployment-5dc964fcf8   Created pod: example-deployment-5dc964fcf8-gbm5t
6m6s        Normal    ScalingReplicaSet      deployment/example-deployment              Scaled up replica set example-deployment-5dc964fcf8 to 1
3m39s       Normal    ScalingReplicaSet      deployment/example-deployment              Scaled up replica set example-deployment-5dc964fcf8 to 1
3m38s       Normal    EnsuringLoadBalancer   service/example                            Ensuring load balancer
3m34s       Normal    EnsuredLoadBalancer    service/example                            Ensured load balancer

Docker文件入口点就像ENTRYPOINT [“ npm”,“ start”] ,带有 CMD [“ tail -f / dev / null /”]

1 个答案:

答案 0 :(得分:0)

它在本地运行。隐式地,它分配 CI =“ true” 标志。但是,在docker-compose stdin_open:true tty:true 中进行设置,在Kubernetes部署文件中,将名为变量 CI 的ENV设置为设置值为“ true”