在Azure Kubernetes服务中部署MVC应用失败,并显示错误-“退后重新启动失败的容器”

时间:2020-05-03 19:46:29

标签: kubernetes kubectl azure-aks azure-kubernetes kubernetes-cluster

将Web应用程序推送到Docker Hub之后,我可以通过命令(使用kubectl部署YAML文件)将Web应用程序手动部署到AKS群集,但是当我尝试通过CI / CD管道自动执行该操作时,该应用程序无法正常运行部署到AKS。 CI / CD级别未记录任何错误,但应用程序部署在AKS中未成功。 AKS仪表板上的错误是-“ 后退重新启动失败的容器”。在广告连播的事件中,事件之一是“ 计算机上已经存在容器图像image_name

用于MVC应用和服务部署的YAML文件如下。

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: some_name
spec:
  selector:
    matchLabels:
      app: mvc
  replicas: 1 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: mvc
    spec:
      containers:
      - name: mvc
        image: my_image_in_DockerHub
        ports:
        - containerPort: 80
        resources:
          limits:
           cpu: "1"
            memory: "200Mi"
          requests:
            cpu: "0.1"
            memory: "100Mi"
        env:
          - name: ConnectionStrings__ProductsContext
            valueFrom:
              secretKeyRef:
                name: some_name_for_secret
                key: some_name_for_db_connection
---
kind: Service
apiVersion: v1
metadata:
      name: some_name
spec:
  selector:
    app: mvc
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: LoadBalancer

以下是由于以下原因而提供的日志:-

kubectl --v=8 logs pod-name

kubectl : I0504 00:39:54.755870   17784 loader.go:359] Config loaded from 
file:  C:\Users\chaitanya/.kube/config
At line:1 char:1
+ kubectl --v=8 logs pod_name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (I0504 
00:39:54....um/.kube/config:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

I0504 00:39:54.804850   17784 round_trippers.go:416] GET 
https://aks-clustername--dns- 
1f3c4666.hcp.eastus2.azmk8s.io:443/api/v1/namespaces/default/pods/pod-name
I0504 00:39:54.804850   17784 round_trippers.go:423] Request Headers:
I0504 00:39:54.804850   17784 round_trippers.go:426]     Accept: 
application/json, */*
I0504 00:39:54.804850   17784 round_trippers.go:426]     User-Agent: 
kubectl.exe/v1.15.5 (windows/amd64) kubernetes/20c265f
I0504 00:39:54.804850   17784 round_trippers.go:426]     Authorization: 
Bearer 
70327cca50fd26087cad64e1eb48590ebf8c159c3b81c033fa20d806b72960a39d3a3a22
de97c8a90 8c6189918ef79aac4637cb2e0927994cfa0c6f5f514bcc8
I0504 00:39:56.178254   17784 round_trippers.go:441] Response Status: 200 OK 
in 1373 milliseconds
I0504 00:39:56.178254   17784 round_trippers.go:444] Response Headers:
I0504 00:39:56.178254   17784 round_trippers.go:447]     Audit-Id: 59d5b365- 
7cb4-455a-abac-82c3079053e9
I0504 00:39:56.178254   17784 round_trippers.go:447]     Content-Type: 
application/json
I0504 00:39:56.178254   17784 round_trippers.go:447]     Content-Length: 3297
I0504 00:39:56.178254   17784 round_trippers.go:447]     Date: Sun, 03 May 
2020 19:09:56 GMT
I0504 00:39:56.184253   17784 request.go:947] Response Body: 
{"kind":"Pod","apiVersion":"v1","metadata":{"name":"pod- 
name","generateName":"some-name-79c6dff5c5-",
"namespace":"default","selfLink":"/api/v1/namespaces/default/pods/pod- 
name","uid":"f461a90f-0fbc-4f1d-b2fc- 
8c539fe70426","resourceVersion":"153797",
"creationTimestamp":"2020-05-03T18:55:50Z","labels":{"app":"mvc","pod- 
template-hash":"79c6dff5c5"},"ownerReferences": 
[{"apiVersion":"apps/v1","kind":"ReplicaSet",
"name":"some-name-79c6dff5c5","uid":"f5fae8a5-e3d6-44b9-98a2- 
13d197789a9f","controller":true,"blockOwnerDeletion":true}]},"spec": 
{"volumes":[{"name":"default-token-xpdcx",
"secret":{"secretName":"default-token- 
xpdcx","defaultMode":420}}],"containers": 
[{"name":"mvc","image":"my_image_in_DockerHub","ports": 
[{"containerPort":80,"protocol":"TCP"}],
"env":[{"name":"ConnectionStrings__ProductsContext","valueFrom":{"secretKeyRef": 
{"name":"some_name_for_secret","key":"some_name_for_db_connection"}}}],"resources":{"limits":{"cpu": 
[truncated 2273 chars]
I0504 00:39:56.192255   17784 round_trippers.go:416] GET 
https://aks-clustername-dns- 
1f3c4666.hcp.eastus2.azmk8s.io:443/api/v1/namespaces/default/pods/pod- 
name/log
I0504 00:39:56.192255   17784 round_trippers.go:423] Request Headers:
I0504 00:39:56.192255   17784 round_trippers.go:426]     Accept: 
application/json, */*
I0504 00:39:56.192255   17784 round_trippers.go:426]     User-Agent: 
kubectl.exe/v1.15.5 (windows/amd64) kubernetes/20c265f
I0504 00:39:56.192255   17784 round_trippers.go:426]     Authorization: 
Bearer 
70327cca50fd26087cad64e1eb48590ebf8c159c3b81c033fa20d806b72960a39d
3a3a22de97c8a908c6189918ef79aac4637cb2e0927994cfa0c6f5f514bcc8
I0504 00:39:56.482026   17784 round_trippers.go:441] Response Status: 200 OK 
in 289 milliseconds
I0504 00:39:56.483003   17784 round_trippers.go:444] Response Headers:
I0504 00:39:56.483003   17784 round_trippers.go:447]     Content-Type: 
text/plain
I0504 00:39:56.483003   17784 round_trippers.go:447]     Date: Sun, 03 May 
2020 19:09:56 GMT
I0504 00:39:56.483003   17784 round_trippers.go:447]     Audit-Id: 149a7b4d- 
562c-4376-adc8-bf7c7a3cfdf5

kubectl描述pod pod名称

Name:           pod-name
Namespace:      default
Priority:       0
Node:           xxx-agentpool-xxxxxxxxxx-1/10.240.0.4
Start Time:     Mon, 04 May 2020 00:25:50 +0530
Labels:         app=mvc
                pod-template-hash=79c6dff5c5
Annotations:    <none>
Status:         Running
IP:             10.244.1.16
Controlled By:  ReplicaSet/pod-79c6dff5c5
Containers:
  mvc:
    Container ID:   docker://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Image:          my_image_in_DockerHub
    Image ID:       docker-pullable://xxxxxxxxxxxxxxxx/xxxxxxx@sha256:5779639a3067e0e31f548761ed3f27ab4c8ce64ac5fa9132ff800a2107969fed
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Mon, 04 May 2020 00:31:47 +0530
      Finished:     Mon, 04 May 2020 00:31:47 +0530
    Ready:          False
    Restart Count:  6
    Limits:
      cpu:     1
      memory:  200Mi
    Requests:
      cpu:     100m
      memory:  100Mi
    Environment:
      ConnectionStrings__ProductsContext:  <set to the key 'some_name_for_db_connection' in secret 'some_name_for_secret'>  Optional: false
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-xpdcx (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-xpdcx:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-xpdcx
    Optional:    false
QoS Class:       Burstable
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  8m52s                   default-scheduler                  Successfully assigned default/pod-name to xxx-agentpool-xxxxxxxx-1
  Normal   Pulling    8m51s                   kubelet, xxx-agentpool-xxxxxxxx-1  Pulling image "my_image_in_DockerHub"
  Normal   Pulled     8m50s                   kubelet, xxx-agentpool-xxxxxxxx-1  Successfully pulled image "my_image_in_DockerHub"
  Normal   Created    7m13s (x5 over 8m50s)   kubelet, xxx-agentpool-xxxxxxxx-1  Created container mvc
  Normal   Started    7m13s (x5 over 8m49s)   kubelet, xxx-agentpool-xxxxxxxx-1  Started container mvc
  Normal   Pulled     7m13s (x4 over 8m48s)   kubelet, xxx-agentpool-xxxxxxxx-1  Container image "my_image_in_DockerHub" already present on machine
  Warning  BackOff    3m50s (x25 over 8m47s)  kubelet, xxx-agentpool-xxxxxxxx-1  Back-off restarting failed container

1 个答案:

答案 0 :(得分:0)

这可能不是解决方案,但应该会有所帮助!第一步

要查找所有吊舱的名称,请运行:kubectl获取吊舱

NAME         READY   STATUS    RESTARTS   AGE
webapp       1/1     Running   15         47h

找到失败或具有该状态的Pod,然后运行

??????? ???? ???????

要获取实际错误并进行修复