Kubernetes Pod 卡在容器创建中

Kubernetes Pod stuck in container creating

我正在尝试在 GCP kubernetes 上部署此 docker-compose 应用程序。

version: "3.5"

x-environment:
  &default-back-environment
  # Database settings
  POSTGRES_DB: taiga
  POSTGRES_USER: taiga
  POSTGRES_PASSWORD: taiga
  POSTGRES_HOST: taiga-db
  # Taiga settings
  TAIGA_SECRET_KEY: "taiga-back-secret-key"
  TAIGA_SITES_SCHEME: "http"
  TAIGA_SITES_DOMAIN: "localhost:9000"
  TAIGA_SUBPATH: "" # "" or "/subpath"
  # Email settings. Uncomment following lines and configure your SMTP server
  # EMAIL_BACKEND: "django.core.mail.backends.smtp.EmailBackend"
  # DEFAULT_FROM_EMAIL: "no-reply@example.com"
  # EMAIL_USE_TLS: "False"
  # EMAIL_USE_SSL: "False"
  # EMAIL_HOST: "smtp.host.example.com"
  # EMAIL_PORT: 587
  # EMAIL_HOST_USER: "user"
  # EMAIL_HOST_PASSWORD: "password"
  # Rabbitmq settings
  # Should be the same as in taiga-async-rabbitmq and taiga-events-rabbitmq
  RABBITMQ_USER: taiga
  RABBITMQ_PASS: taiga
  # Telemetry settings
  ENABLE_TELEMETRY: "True"

x-volumes:
  &default-back-volumes
  - taiga-static-data:/taiga-back/static
  - taiga-media-data:/taiga-back/media
  # - ./config.py:/taiga-back/settings/config.py


services:
  taiga-db:
    image: postgres:12.3
    environment:
      POSTGRES_DB: taiga
      POSTGRES_USER: taiga
      POSTGRES_PASSWORD: taiga
    volumes:
      - taiga-db-data:/var/lib/postgresql/data
    networks:
      - taiga

  taiga-back:
    image: taigaio/taiga-back:latest
    environment: *default-back-environment
    volumes: *default-back-volumes
    networks:
      - taiga
    depends_on:
      - taiga-db
      - taiga-events-rabbitmq
      - taiga-async-rabbitmq

  taiga-async:
    image: taigaio/taiga-back:latest
    entrypoint: ["/taiga-back/docker/async_entrypoint.sh"]
    environment: *default-back-environment
    volumes: *default-back-volumes
    networks:
      - taiga
    depends_on:
      - taiga-db
      - taiga-back
      - taiga-async-rabbitmq

  taiga-async-rabbitmq:
    image: rabbitmq:3.8-management-alpine
    environment:
      RABBITMQ_ERLANG_COOKIE: secret-erlang-cookie
      RABBITMQ_DEFAULT_USER: taiga
      RABBITMQ_DEFAULT_PASS: taiga
      RABBITMQ_DEFAULT_VHOST: taiga
    volumes:
      - taiga-async-rabbitmq-data:/var/lib/rabbitmq
    networks:
      - taiga

  taiga-front:
    image: taigaio/taiga-front:latest
    environment:
      TAIGA_URL: "http://localhost:9000"
      TAIGA_WEBSOCKETS_URL: "ws://localhost:9000"
      TAIGA_SUBPATH: "" # "" or "/subpath"
    networks:
      - taiga
    # volumes:
    #   - ./conf.json:/usr/share/nginx/html/conf.json

  taiga-events:
    image: taigaio/taiga-events:latest
    environment:
      RABBITMQ_USER: taiga
      RABBITMQ_PASS: taiga
      TAIGA_SECRET_KEY: "taiga-back-secret-key"
    networks:
      - taiga
    depends_on:
      - taiga-events-rabbitmq

  taiga-events-rabbitmq:
    image: rabbitmq:3.8-management-alpine
    environment:
      RABBITMQ_ERLANG_COOKIE: secret-erlang-cookie
      RABBITMQ_DEFAULT_USER: taiga
      RABBITMQ_DEFAULT_PASS: taiga
      RABBITMQ_DEFAULT_VHOST: taiga
    volumes:
      - taiga-events-rabbitmq-data:/var/lib/rabbitmq
    networks:
      - taiga

  taiga-protected:
    image: taigaio/taiga-protected:latest
    environment:
      MAX_AGE: 360
      SECRET_KEY: "taiga-back-secret-key"
    networks:
      - taiga

  taiga-gateway:
    image: nginx:1.19-alpine
    ports:
      - "9000:80"
    volumes:
      - ./taiga-gateway/taiga.conf:/etc/nginx/conf.d/default.conf
      - taiga-static-data:/taiga/static
      - taiga-media-data:/taiga/media
    networks:
      - taiga
    depends_on:
      - taiga-front
      - taiga-back
      - taiga-events

volumes:
  taiga-static-data:
  taiga-media-data:
  taiga-db-data:
  taiga-async-rabbitmq-data:
  taiga-events-rabbitmq-data:

networks:
  taiga:

我已经使用 Kompose 生成了我的 kubernetes 部署文件。所有的pods都是运行裸二。但是,除此之外,它们没有显示任何错误。

Unable to attach or mount volumes: unmounted volumes=[taiga-static-data taiga-media-data], unattached volumes=[kube-api-access-9c74v taiga-gateway-claim0 taiga-static-data taiga-media-data]: timed out waiting for the condition

Pod 状态

taiga-async-6c7d9dbd7b-btv79             1/1     Running             19         16h
taiga-async-rabbitmq-86979cf759-lvj2m    1/1     Running             0          16h
taiga-back-7bc574768d-hst2v              0/1     ContainerCreating   0          6m34s
taiga-db-59b554854-qdb65                 1/1     Running             0          16h
taiga-events-74f494df97-8rpjd            1/1     Running             0          16h
taiga-events-rabbitmq-7f558ddf88-wc2js   1/1     Running             0          16h
taiga-front-6f66c475df-8cmf6             1/1     Running             0          16h
taiga-gateway-77976dc77-w5hp4            0/1     ContainerCreating   0          3m6s
taiga-protected-7794949d49-crgbt         1/1     Running             0          16h

挂载卷时出现问题,我很确定 taiga-backtaiga-db 共享一个卷。

这是我的 Kompose 文件。

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert -f docker-compose.yml
    kompose.version: 1.26.1 (a9d05d509)
  creationTimestamp: null
  labels:
    io.kompose.service: taiga-gateway
  name: taiga-gateway
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: taiga-gateway
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert -f docker-compose.yml
        kompose.version: 1.26.1 (a9d05d509)
      creationTimestamp: null
      labels:
        io.kompose.network/taiga: "true"
        io.kompose.service: taiga-gateway
    spec:
      containers:
        - image: nginx:1.19-alpine
          name: taiga-gateway
          ports:
            - containerPort: 80
          resources: {}
          volumeMounts:
            - mountPath: /etc/nginx/conf.d/default.conf
              
              name: taiga-gateway-claim0
            - mountPath: /taiga/static
              name: taiga-static-data
              
            - mountPath: /taiga/media
              name: taiga-media-data
              
      restartPolicy: Always
      volumes:
        - name: taiga-gateway-claim0
          persistentVolumeClaim:
            claimName: taiga-gateway-claim0
        - name: taiga-static-data
          persistentVolumeClaim:
            claimName: taiga-static-data
        - name: taiga-media-data
          persistentVolumeClaim:
            claimName: taiga-media-data
status: {}

如果我能修好一个,也许我也能找出另一个吊舱。这是应用程序 https://github.com/kaleidos-ventures/taiga-docker。欢迎任何指点。 kubectl describe pod输出

Name:           taiga-gateway-77976dc77-w5hp4
Namespace:      default
Priority:       0
Node:           gke-taiga-cluster-default-pool-9e5ed1f4-0hln/10.128.0.18
Start Time:     Wed, 13 Apr 2022 05:32:10 +0000
Labels:         io.kompose.network/taiga=true
                io.kompose.service=taiga-gateway
                pod-template-hash=77976dc77
Annotations:    kompose.cmd: kompose convert -f docker-compose.yml
                kompose.version: 1.26.1 (a9d05d509)
Status:         Pending
IP:
IPs:            <none>
Controlled By:  ReplicaSet/taiga-gateway-77976dc77
Containers:
  taiga-gateway:
    Container ID:
    Image:          nginx:1.19-alpine
    Image ID:
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /etc/nginx/conf.d/default.conf from taiga-gateway-claim0 (rw)
      /taiga/media from taiga-media-data (rw)
      /taiga/static from taiga-static-data (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9c74v (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  taiga-gateway-claim0:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  taiga-gateway-claim0
    ReadOnly:   false
  taiga-static-data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  taiga-static-data
    ReadOnly:   false
  taiga-media-data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  taiga-media-data
    ReadOnly:   false
  kube-api-access-9c74v:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason       Age                  From               Message
  ----     ------       ----                 ----               -------
  Normal   Scheduled    16m                  default-scheduler  Successfully assigned default/taiga-gateway-77976dc77-w5hp4 to gke-taiga-cluster-default-pool-9e5ed1f4-0hln
  Warning  FailedMount  5m49s (x4 over 14m)  kubelet            Unable to attach or mount volumes: unmounted volumes=[taiga-static-data taiga-media-data], unattached volumes=[taiga-gateway-claim0 taiga-static-data taiga-media-data kube-api-access-9c74v]: timed out waiting for the condition
  Warning  FailedMount  81s (x3 over 10m)    kubelet            Unable to attach or mount volumes: unmounted volumes=[taiga-static-data taiga-media-data], unattached volumes=[kube-api-access-9c74v taiga-gateway-claim0 taiga-static-data taiga-media-data]: timed out waiting for the condition

您很可能没有正确配置 PVC,并且容器正在尝试装载声明,但声明未绑定到 PV。

请确保 taiga-static-data 和 taiga-media-data pvc 绑定到它们各自的 pv。

问题是持久卷未绑定到 pod,因此 pod 无法启动。确保配置存储并创建持久卷。

volumes:
  taiga-static-data:
  taiga-media-data:
  taiga-db-data:
  taiga-async-rabbitmq-data:
  taiga-events-rabbitmq-data:

根据您的来源 docker 规范,您可以将 persistentVolumeClaim 替换为 emptyDir

volumes:
- name: taiga-gateway-claim0
  emptyDir: {}
- name: taiga-static-data
  emptyDir: {}
- name: taiga-media-data
  emptyDir: {}

或者如果你想保留你的数据(继续使用persistentVolumeClaim),你应该先创建 PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: taiga-gateway-claim0
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: taiga-static-data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: taiga-media-data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  ...

以上规范将使用 GKE 集群上的默认 StorageClass 为您的 pod 动态配置 3 个持久卷。