4

我正在尝试使用 Skaffold 在我的本地机器上部署一个微服务系统。

入口-srv.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
  rules:
    - host: ticketing.dot
      http:
        paths:
          - path: /api/users/?(.*)
            backend:
              serviceName: auth-srv
              servicePort: 3000

auth-depl.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: ****MYDOCKERID****/auth
          env:
            - name: JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: jwt-secret
                  key: JWT_KEY

---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000

auth-mongo-depl.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-mongo-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth-mongo
  template:
    metadata:
      labels:
        app: auth-mongo
    spec:
      containers:
        - name: auth-mongo
          image: mongo
---
apiVersion: v1
kind: Service
metadata:
  name: auth-mongo-srv
spec:
  selector:
    app: auth-mongo
  ports:
    - name: db
      protocol: TCP
      port: 27017
      targetPort: 27017

我已按照手册中的指南进行操作:

https://kubernetes.github.io/ingress-nginx/deploy/

并点击:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.34.0/deploy/static/provider/cloud/deploy.yaml

然而 Skaffold 继续终止部署:

[34mListing files to watch...[0m
[34m - ****MYDOCKERID****/auth
[0m[34mGenerating tags...[0m
[34m - ****MYDOCKERID****/auth -> [0m****MYDOCKERID****/auth:683e8db
[34mChecking cache...[0m
[34m - ****MYDOCKERID****/auth: [0m[32mFound Locally[0m
[34mTags used in deployment:[0m
[34m - ****MYDOCKERID****/auth -> [0m****MYDOCKERID****/auth:3c4bb66ff693320b5fac3fde91906768f8b54b968813b226822d057d1dd3a995
[34mStarting deploy...[0m
 - deployment.apps/auth-depl created
 - service/auth-srv created
 - deployment.apps/auth-mongo-depl created
 - service/auth-mongo-srv created
 - ingress.extensions/ingress-service created
[34mWaiting for deployments to stabilize...[0m
 - deployment/auth-depl:
 - deployment/auth-mongo-depl:
 - deployment/auth-depl: waiting for rollout to finish: 0 of 1 updated replicas are available...
 - deployment/auth-mongo-depl: waiting for rollout to finish: 0 of 1 updated replicas are available...
 - deployment/auth-mongo-depl is ready. [1/2 deployment(s) still pending]
 - deployment/auth-depl failed. Error: could not stabilize within 2m0s: context deadline exceeded.
[34mCleaning up...[0m
 - deployment.apps "auth-depl" deleted
 - service "auth-srv" deleted
 - deployment.apps "auth-mongo-depl" deleted
 - service "auth-mongo-srv" deleted
 - ingress.extensions "ingress-service" deleted
[31mexiting dev mode because first deploy failed: 1/2 deployment(s) failed[0m

我们如何解决这个烦人的问题?

编辑 9:44 AM 以色列时间:

C:\Development-T410\Micro Services - JAN>kubectl get pods
NAME                                 READY   STATUS                       RESTARTS   AGE
auth-depl-645bbf7b9d-llp2q           0/1     CreateContainerConfigError   0          115s
auth-depl-c6c765d7c-7wvcg            0/1     CreateContainerConfigError   0          28m
auth-mongo-depl-6b594c4847-4kzzt     1/1     Running                      0          115s
client-depl-5888f95b59-vznh6         1/1     Running                      0          114s
nats-depl-7dfccdf5-874vm             1/1     Running                      0          114s
orders-depl-74f4d48559-cbwlp         0/1     CreateContainerConfigError   0          114s
orders-depl-78fc845b4-9tfml          0/1     CreateContainerConfigError   0          28m
orders-mongo-depl-688676d675-lrvhp   1/1     Running                      0          113s
tickets-depl-7cc7ddbbff-z9pvc        0/1     CreateContainerConfigError   0          113s
tickets-depl-8574fc8f9b-tm6p4        0/1     CreateContainerConfigError   0          28m
tickets-mongo-depl-b95f45947-hf6wq   1/1     Running                      0          113s

C:\Development-T410\Micro Services>kubectl logs auth-depl-c6c765d7c-7wvcg
Error from server (BadRequest): container "auth" in pod "auth-depl-c6c765d7c-7wvcg" is waiting to start: CreateContainerConfigError
4

2 回答 2

5

看起来您的auth-depl部署失败了。可能容器正在崩溃或出错。要调试,您可以查看 pod 日志

$ kubectl logs auth-depl-xxxxxxxxxx-xxxxx

确保使用该--cleanup=false选项运行 skaffold,以便进行调试。例如,

$ skaffold dev --cleanup=false

更新:

根据日志,您的 Kubernetes Secret 及其定义方式可能存在问题,可能是格式或 YAML 格式。这个答案揭示了问题可能是什么的一些细节:Pod status as `CreateContainerConfigError` in Minikube cluster

于 2020-07-14T05:57:00.627 回答
0

您应该在部署文件中添加 mongo 映像的环境变量

 env:
        - name: MONGO_INITDB_ROOT_USERNAME
          value: root
        - name: MONGO_INITDB_ROOT_PASSWORD
          value: "rootuser"
于 2020-08-02T16:41:08.457 回答