How Can I Achieve Compatibility Between ExtendPathMode and Kubernetes client-go?
Application Scenario
The Kubernetes pod structure does not contain ExtendPathMode. Therefore, when a user calls the API for creating a pod or deployment by using client-go, the created pod does not contain ExtendPathMode. CCE provides a solution to ensure compatibility with the Kubernetes client-go.
Solution
- When creating a pod, you need to add kubernetes.io/extend-path-mode to annotation of the pod.
- When creating a Deployment, you need to add kubernetes.io/extend-path-mode to kubernetes.io/extend-path-mode in the template.
The following is an example YAML of creating a pod. After the kubernetes.io/extend-path-mode keyword is added to annotation, the containername, name, and mountpath fields are matched, and the corresponding extendpathmode is added to volumeMount.
apiVersion: v1kind: Podmetadata:name: test-8b59d5884-96vdzgenerateName: test-8b59d5884-namespace: defaultselfLink: /api/v1/namespaces/default/pods/test-8b59d5884-96vdzlabels:app: testpod-template-hash: 8b59d5884annotations: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/v1kind: ReplicaSetname: test-8b59d5884uid: 2633020b-cd23-11e9-8f83-fa163e592534controller: trueblockOwnerDeletion: truespec:volumes:- name: vol-156738843032165499hostPath:path: /tmptype: ''- name: default-token-4s959secret:secretName: default-token-4s959defaultMode: 420containers:- name: container-0image: 'nginx:latest'env:- name: PAAS_APP_NAMEvalue: test- name: PAAS_NAMESPACEvalue: default- name: PAAS_PROJECT_IDvalue: b6315dd3d0ff4be5b31a963256794989resources:limits:cpu: 250mmemory: 512Mirequests:cpu: 250mmemory: 512MivolumeMounts:- name: vol-156738843032165499mountPath: /tmpextendPathMode: PodUID- name: default-token-4s959readOnly: truemountPath: /var/run/secrets/kubernetes.io/serviceaccountterminationMessagePath: /dev/termination-logterminationMessagePolicy: FileimagePullPolicy: AlwaysrestartPolicy: AlwaysterminationGracePeriodSeconds: 30dnsPolicy: ClusterFirstserviceAccountName: defaultserviceAccount: defaultnodeName: 192.168.0.24securityContext: {}imagePullSecrets:- name: default-secret- name: default-secretaffinity: {}schedulerName: default-schedulertolerations:- key: node.kubernetes.io/not-readyoperator: Existseffect: NoExecutetolerationSeconds: 300- key: node.kubernetes.io/unreachableoperator: Existseffect: NoExecutetolerationSeconds: 300priority: 0dnsConfig:options:- name: timeoutvalue: ''- name: ndotsvalue: '5'- name: single-request-reopenenableServiceLinks: true
Parameter | Type | Description |
---|---|---|
containername | String | Name of a container. |
name | String | Name of a volume. |
mountpath | String | Mount path. |
extendpathmode | String | A third-level directory is added to the created volume directory/subdirectory to facilitate the obtaining of a single pod output file. The following types are supported.
|
- Application Scenario
- Solution