云容器引擎 CCE-使用kubectl部署带极速文件存储卷的有状态工作负载:操作步骤

时间:2023-11-01 16:25:54

操作步骤

  1. 参照创建文件存储卷中操作创建极速文件存储卷,记录极速文件存储卷名称。
  2. 请参见通过kubectl连接集群,使用kubectl连接集群。
  3. 新建一个文件,用于创建工作负载。假设文件名为efs-statefulset-example.yaml

    touch efs-statefulset-example.yaml

    vi efs-statefulset-example.yaml

    yaml示例如下:

    apiVersion: apps/v1kind: StatefulSetmetadata:  name: efs-statefulset-example  namespace: defaultspec:  replicas: 1  selector:    matchLabels:      app: efs-statefulset-example  template:    metadata:      annotations:        metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"","path":"","port":"","names":""}]'        pod.alpha.kubernetes.io/initialized: 'true'      labels:        app: efs-statefulset-example    spec:      containers:        - image: 'nginx:1.0.0'          name: container-0          resources:            requests: {}            limits: {}          env:            - name: PAAS_APP_NAME              value: efs-statefulset-example            - name: PAAS_NAMESPACE              value: default            - name: PAAS_PROJECT_ID              value: b18296881cc34f929baa8b9e95abf88b          volumeMounts:            - name: efs-statefulset-example              mountPath: /tmp              readOnly: false              subPath: ''      imagePullSecrets:        - name: default-secret      terminationGracePeriodSeconds: 30      volumes:        - persistentVolumeClaim:            claimName: cce-efs-import-jnr481gm-3y5o          name: efs-statefulset-example      affinity: {}      tolerations:        - key: node.kubernetes.io/not-ready          operator: Exists          effect: NoExecute          tolerationSeconds: 300        - key: node.kubernetes.io/unreachable          operator: Exists          effect: NoExecute          tolerationSeconds: 300  podManagementPolicy: OrderedReady  serviceName: test  updateStrategy:    type: RollingUpdate
    表1 关键参数说明

    参数

    描述

    replicas

    实例数。

    name

    新建工作负载的名称。

    image

    新建工作负载使用的镜像。

    mountPath

    容器内挂载路径。

    serviceName

    工作负载对应的服务,服务创建过程请参见创建有状态负载(StatefulSet)

    claimName

    已有PVC名称。

    spec.template.spec.containers.volumeMounts.name和spec.template.spec.volumes.name有映射关系,必须保持一致。

  4. 创建有状态工作负载。

    kubectl create -f efs-statefulset-example.yaml

support.huaweicloud.com/usermanual-cce/cce_10_0334.html