¿Cómo puedo lograr la compatibilidad entre ExtendPathMode y Kubernetes client-go?
Escenario
La estructura de pods de Kubernetes no contiene ExtendPathMode. Por lo tanto, cuando un usuario invoca a la API para crear un pod o despliegue usando client-go, el pod creado no contiene ExtendPathMode. CCE proporciona una solución para garantizar la compatibilidad con Kubernetes client-go.
Solución
- Cuando crea un pod, necesita agregar kubernetes.io/extend-path-mode al annotation del pod.
- Al crear una Deployment, debe agregar kubernetes.io/extend-path-mode a kubernetes.io/extend-path-mode en la plantilla.
El siguiente es un ejemplo YAML de creación de un pod. Después de agregar la palabra clave kubernetes.io/extend-path-mode a annotation se hacen coincidir los campos containername, name y mountpath y el extendpathmode correspondiente se agrega a volumeMount.
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
|
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
containername |
String |
Nombre de un contenedor. |
|
name |
String |
Nombre de un volumen. |
|
mountpath |
String |
Camino de monte. |
|
extendpathmode |
String |
Se agrega un directorio de tercer nivel al directorio/subdirectorio de volumen creado para facilitar la obtención de un archivo de salida del pod único. Se admiten los cinco tipos siguientes. Para obtener más información, consulte Logs de contenedores.
|