pod-往业务容器注入sidecar容器

题目要求全部达成但是就是通不过测试,有可能和前几次一样都是输入的格式有问题导致验证不通过。

你输出总结:

  • my-pvc-cka 和 PV 都 Bound 且容量是 100Mi
  • my-pod-cka 状态是 2/2 Running,说明两个容器都成功启动了。
  • nginx-container 存在,busybox-sidecar 存在。
  • busybox-sidecarCommandtail -f /dev/null
  • nginx-container 的挂载:
    • /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-7jjff (ro) (正常)
    • /var/www/html from shared-storage (rw) (Nginx 默认挂载,rw 可写)
    • /var/www/shared from shared-storage (rw) (新增加的共享挂载,可写,符合预期)
  • busybox-sidecar 的挂载:
    • /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-7jjff (ro) (正常)
    • /var/www/shared from shared-storage (ro) (共享挂载,只读,符合预期)
  • Volumes 定义: shared-storage 卷是 PersistentVolumeClaim 类型,指向 my-pvc-cka,并且 ReadOnly: false (这是卷本身的属性,容器可以分别设置自己的读写权限,所以这个也符合预期)。

describe 的输出看,你的 Pod 配置完美符合了题目中的所有要求!

  • Sidecar 容器已添加 (busybox-sidecar)。
  • Sidecar 容器使用 busybox 镜像并执行 tail -f /dev/null
  • shared-storage 卷在两个容器中都挂载到了 /var/www/shared
  • busybox-sidecar/var/www/shared(ro) (只读)。
controlplane:~$ cat pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: my-pod-cka
spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: nginx-container
    volumeMounts:
    - mountPath: /var/www/html
      name: shared-storage
    - mountPath: /var/www/shared
      name: shared-storage
  - name: busybox-sidecar
    image: busybox
    command: ["tail","-f","/dev/null"]
    volumeMounts:
    - mountPath: /var/www/shared
      name: shared-storage
      readOnly: true
  volumes:
  - name: shared-storage
    persistentVolumeClaim:
      claimName: my-pvc-cka
controlplane:~$ kubectl describe pod my-pod-cka 
Name:             my-pod-cka
Namespace:        default
Priority:         0
Service Account:  default
Node:             node01/172.30.2.2
Start Time:       Mon, 26 May 2025 10:34:01 +0000
Labels:           <none>
Annotations:      cni.projectcalico.org/containerID: 999b5f29b825021747fbdbfa83e4a9a5262068f516253325c7c679bc8bc448a8
                  cni.projectcalico.org/podIP: 192.168.1.8/32
                  cni.projectcalico.org/podIPs: 192.168.1.8/32
Status:           Running
IP:               192.168.1.8
IPs:
  IP:  192.168.1.8
Containers:
  nginx-container:
    Container ID:   containerd://d853d4a8d23702e0d8841aadef2d608c1c07fec7975b44b8263525989f324dcf
    Image:          nginx
    Image ID:       docker.io/library/nginx@sha256:fb39280b7b9eba5727c884a3c7810002e69e8f961cc373b89c92f14961d903a0
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Mon, 26 May 2025 10:34:02 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-cq4b2 (ro)
      /var/www/html from shared-storage (rw)
      /var/www/shared from shared-storage (rw)
  busybox-sidecar:
    Container ID:  containerd://f5c07e766dc2042ab1e12cc08a6f19eb68cc66bd3b10b617cab7063b50e70c9a
    Image:         busybox
    Image ID:      docker.io/library/busybox@sha256:f64ff79725d0070955b368a4ef8dc729bd8f3d8667823904adcb299fe58fc3da
    Port:          <none>
    Host Port:     <none>
    Command:
      tail
      -f
      /dev/null
    State:          Running
      Started:      Mon, 26 May 2025 10:34:02 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-cq4b2 (ro)
      /var/www/shared from shared-storage (ro)
Conditions:
  Type                        Status
  PodReadyToStartContainers   True 
  Initialized                 True 
  Ready                       True 
  ContainersReady             True 
  PodScheduled                True 
Volumes:
  shared-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  my-pvc-cka
    ReadOnly:   false
  kube-api-access-cq4b2:
    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  3m59s  default-scheduler  Successfully assigned default/my-pod-cka to node01
  Normal  Pulling    3m59s  kubelet            Pulling image "nginx"
  Normal  Pulled     3m58s  kubelet            Successfully pulled image "nginx" in 258ms (258ms including waiting). Image size: 72402122 bytes.
  Normal  Created    3m58s  kubelet            Created container: nginx-container
  Normal  Started    3m58s  kubelet            Started container nginx-container
  Normal  Pulling    3m58s  kubelet            Pulling image "busybox"
  Normal  Pulled     3m58s  kubelet            Successfully pulled image "busybox" in 255ms (255ms including waiting). Image size: 2156518 bytes.
  Normal  Created    3m58s  kubelet            Created container: busybox-sidecar
  Normal  Started    3m58s  kubelet            Started container busybox-sidecar
controlplane:~$ kubectl get pvc,pv,sc
NAME                               STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
persistentvolumeclaim/my-pvc-cka   Bound    pvc-7f62040f-7b22-45d0-99cb-7dee8e5fcc8e   100Mi      RWO            local-path     <unset>                 43m

NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                STORAGECLASS   VOLUMEATTRIBUTESCLASS   REASON   AGE
persistentvolume/pvc-7f62040f-7b22-45d0-99cb-7dee8e5fcc8e   100Mi      RWO            Delete           Bound    default/my-pvc-cka   local-path     <unset>                          36m

NAME                                               PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
storageclass.storage.k8s.io/local-path (default)   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  14d
controlplane:~$ 
posted on 2025-05-26 19:13  Leo-Yide  阅读(27)  评论(0)    收藏  举报