文档首页> 云容器引擎 CCE> 常见问题> 存储管理> Pod接口ExtendPathMode: PodUID如何与社区client-go兼容?
更新时间:2022-09-05 GMT+08:00

Pod接口ExtendPathMode: PodUID如何与社区client-go兼容?

使用场景

社区Pod结构体中没有ExtendPathMode,用户使用client-go调用创建pod或deployment的API接口时,创建的pod中没有ExtendPathMode。为了与社区的client-go兼容,CCE提供了如下解决方案。

解决方案

  • 创建pod时,在pod的annotation中需增加kubernetes.io/extend-path-mode。
  • 创建deployment时,需要在template中的annotation增加kubernetes.io/extend-path-mode

如下为创建pod的yaml示例,在annotation中添加kubernetes.io/extend-path-mode关键字后,完全匹配到containername,name,mountpath三个字段,则会在volumeMount中增加对应的extendpathmode

apiVersion: v1
kind: Pod
metadata:
  name: test-8b59d5884-96vdz
  generateName: test-8b59d5884-
  namespace: default
  selfLink: /api/v1/namespaces/default/pods/test-8b59d5884-96vdz
  labels:
    app: test
    pod-template-hash: 8b59d5884
  annotations:
    kubernetes.io/extend-path-mode: '[{"containername":"container-0","name":"vol-156738843032165499","mountpath":"/tmp","extendpathmode":"PodUID"}]'
    metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"","path":"","port":"","names":""}]'
  ownerReferences:
    - apiVersion: apps/v1
      kind: ReplicaSet
      name: test-8b59d5884
      uid: 2633020b-cd23-11e9-8f83-fa163e592534
      controller: true
      blockOwnerDeletion: true
spec:
  volumes:
    - name: vol-156738843032165499
      hostPath:
        path: /tmp
        type: ''
    - name: default-token-4s959
      secret:
        secretName: default-token-4s959
        defaultMode: 420
  containers:
    - name: container-0
      image: 'nginx:latest'
      env:
        - name: PAAS_APP_NAME
          value: test
        - name: PAAS_NAMESPACE
          value: default
        - name: PAAS_PROJECT_ID
          value: b6315dd3d0ff4be5b31a963256794989
      resources:
        limits:
          cpu: 250m
          memory: 512Mi
        requests:
          cpu: 250m
          memory: 512Mi
      volumeMounts:
        - name: vol-156738843032165499
          mountPath: /tmp
          extendPathMode: PodUID
        - name: default-token-4s959
          readOnly: true
          mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      imagePullPolicy: Always
  restartPolicy: Always
  terminationGracePeriodSeconds: 30
  dnsPolicy: ClusterFirst
  serviceAccountName: default
  serviceAccount: default
  nodeName: 192.168.0.24
  securityContext: {}
  imagePullSecrets:
    - name: default-secret
    - name: default-secret
  affinity: {}
  schedulerName: default-scheduler
  tolerations:
    - key: node.kubernetes.io/not-ready
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
    - key: node.kubernetes.io/unreachable
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
  priority: 0
  dnsConfig:
    options:
      - name: timeout
        value: ''
      - name: ndots
        value: '5'
      - name: single-request-reopen
  enableServiceLinks: true
表1 关键参数说明

参数

参数类型

描述

containername

String

容器名称。

name

String

volume的名称。

mountpath

String

挂载路径

extendpathmode

String

将在已创建的“卷目录/子目录”中增加一个三级目录,便于更方便获取单个Pod输出的文件。

支持如下五种类型,详情请参考容器日志

  • None:不配置拓展路径。
  • PodUID:Pod的ID。
  • PodName:Pod的名称。
  • PodUID/ContainerName:Pod的ID/容器名称。
  • PodName/ContainerName:Pod名称/容器名称。

存储管理 所有常见问题

more