Loading
close

使用Yaml创建资源

time 更新时间:2022-02-16 15:27:06

内容要求

若希望通过Yaml文件创建资源并与某个应用产生关联,需要在创建资源时通过 app.kubernetes.io/name:应用名称 标签指定所关联的目标应用。此处以创建名称为“deployment-demo”的“部署”类型工作负载并关联到名称为“app-demo”的应用为例,Yaml内容示例如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    ecns.es.io/workload: deployment-deployment-demo
   app.kubernetes.io/name: app-demo  #Replace app-demo with the name of the target application you want to associate with.
  name: deployment-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      ecns.es.io/workload: deployment-deployment-demo
  template:
    metadata:
      labels:
        ecns.es.io/workload: deployment-deployment-demo
    spec:
      containers:
      - env:
        - name: username
          valueFrom:
            secretKeyRef:
              key: username
              name: secrets-demo
        - name: password
          valueFrom:
            secretKeyRef:
              key: password
              name: secrets-demo
        image: hub.ecns.io/wuzs01/nginx:latest
        imagePullPolicy: IfNotPresent
        name: nginx
        volumeMounts:
        - mountPath: /tmp/start.sh
          name: configmap-demo
          readOnly: true
          subPath: start.sh
        - mountPath: /data
          name: pvc-demo
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          defaultMode: 292
          name: configmap-demo
        name: configmap-demo
      - name: pvc-demo
        persistentVolumeClaim:
          claimName: pvc-demo

操作步骤

  1. 在支持使用Yaml创建资源的页面单击右下角的“Yaml”图标,跳转至“导入Yaml”页面。
  2. 单击编辑区域右上角的“导入”图标,选择本地存储的Yaml文件。
  3. 请关注调试结果,调试主要针对格式校验,若有错误可点击错误信息,跳至目标行进行修改。
  4. 调试通过后,单击 导入 完成操作。
此篇文章对你是否有帮助?
没帮助
locked-file

您暂无权限访问该产品