php 创建状态容器并启动容器的Pod

e0uiprwp  于 2023-10-15  发布在  PHP
关注(0)|答案(1)|浏览(92)

我有一个运行版本1.28的EKS集群,在那里我遇到了与php-fpm pod相关的问题。
我的pod即使在容器成功启动并生成日志后,仍处于“容器创建”状态。

Name:             api-test-php-5965d59686-ldd7s
Namespace:        api-test-producao
Priority:         0
Service Account:  default
Node:             ip-172-81-11-245.sa-east-1.compute.internal/172.81.11.245
Start Time:       Mon, 09 Oct 2023 17:37:06 -0300
Labels:           app=api-test-php
                  pod-template-hash=5965d59686
Annotations:      co.elastic.logs/enabled: true
Status:           Pending
IP:               
IPs:              <none>
Controlled By:    ReplicaSet/api-test-php-5965d59686
Containers:
  api-test-php:
    Container ID:   
    Image:          ***********.dkr.ecr.sa-east-1.amazonaws.com/api-test:php-90
    Image ID:       
    Port:           9000/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Limits:
      cpu:     800m
      memory:  256Mi
    Requests:
      cpu:     500m
      memory:  128Mi
    Environment Variables from:
      api-test-php  ConfigMap  Optional: false
    Environment:     <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-kl7xj (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-kl7xj:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Burstable
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         44s                  default-scheduler  Successfully assigned api-test-producao/api-test-php-5965d59686-ldd7s to ip-172-81-11-245.sa-east-1.compute.internal
  Normal   Pulling           43s                  kubelet            Pulling image "814635504079.dkr.ecr.sa-east-1.amazonaws.com/api-test:php-90"
  Normal   Pulled            35s                  kubelet            Successfully pulled image "814635504079.dkr.ecr.sa-east-1.amazonaws.com/api-test:php-90" in 7.74s (7.74s including waiting)
  Normal   Created           35s                  kubelet            Created container api-test-php
  Normal   Started           35s                  kubelet            Started container api-test-php

有没有人以前遇到过这种情况,或者可以帮助识别错误?
我试过很多方法。唯一有效的方法是使用Docker Hub中的干净镜像,更改从中提取镜像的存储库。

qltillow

qltillow1#

我找到解决办法了。
在我的部署中,我正在创建Laravel日志文件。这些命令在eks 1.21上运行良好。在eks 1.28中,由于某种原因,我不得不将“sudo”添加到“tail”命令中。
下面是我的修正和现在的功能部署。谢谢你的帮助

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: $K8S_DEPLOY_NAME_PHP
  namespace: $K8S_NAMESPACE
  labels:
    app: $K8S_APP_NAME_PHP
    role: $K8S_APP_ROLE
  annotations:
    co.elastic.logs/enabled: $ELASTIC_ANNOTATIONS_HINTS
spec:
  #replicas: $K8S_APP_SCALE_MIN
  strategy:
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 0
  replicas: $K8S_APP_SCALE_MIN_PHP
  selector:
    matchLabels:
      app: $K8S_APP_NAME_PHP
  template:
    metadata:
      labels:
        app: $K8S_APP_NAME_PHP
      annotations:
        co.elastic.logs/enabled: $ELASTIC_ANNOTATIONS_HINTS
    spec:
      containers:
        - name: $K8S_DEPLOY_NAME_PHP
          image: $K8S_DEPLOY_IMAGE_NAME_PHP:$K8S_DEPLOY_IMAGE_TAG_PHP
          lifecycle:
              postStart:
                exec:
                  command:
                      - /bin/bash
                      - -c
                      - >
                          touch /var/www/storage/logs/laravel.log &&
                          chgrp -R www-data /var/www/bootstrap/ /var/www/storage/ /var/www/storage/logs/ &&
                          chmod -R g+w /var/www/bootstrap/ /var/www/storage/ /var/www/storage/logs/ &&
                          sudo tail -f /var/www/storage/logs/laravel.log > /proc/1/fd/2 &
          resources:
            requests:
              cpu: $K8S_REQUESTS_CPU_PHP
              memory: $K8S_REQUESTS_MEMORY_PHP
            limits:
              cpu: $K8S_LIMITS_CPU_PHP
              memory: $K8S_LIMITS_MEMORY_PHP
          ports:
          - containerPort: $K8S_DEPLOY_IMAGE_PORT_PHP
          envFrom:
          - configMapRef:
              name: $K8S_DEPLOY_NAME_PHP

相关问题