Kubernetes - How to define ConfigMap built using a file in a yaml?

前端 未结 3 2127
失恋的感觉
失恋的感觉 2020-12-14 08:49

At present I am creating a configmap from the file config.json by executing:

kubectl create configmap jksconfig --from-file=config.json

I w

3条回答
  •  情深已故
    2020-12-14 09:27

    Here is an example of a ConfigMap that is attached to a Deployment:

    ConfigMap:

    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: jksconfig
    data:
      config.json: |-
    {{ .Files.Get "config.json" | indent 4 }}
    

    Deployment:

    ---
    apiVersion: apps/v1beta2
    kind: Deployment
    metadata:
      name: jksapp
      labels:
        app: jksapp
    spec:
      selector:
        matchLabels:
          app: jksapp
      template:
        metadata:
          labels:
            app: jksapp
          containers:
            - name: jksapp
              image: jksapp:1.0.0
              ports:
                - containerPort: 8080
              volumeMounts:
                - name: config #The name(key) value must match pod volumes name(key) value 
                  mountPath: /path/to/config.json
          volumes:
            - name: config
              configMap:
                name: jksconfig
    

提交回复
热议问题