how to pass environment variable in kubectl deployment?

前端 未结 6 494
失恋的感觉
失恋的感觉 2020-12-20 12:44

I am setting up the kubernetes setup for django webapp.

I am passing environment variable while creating deployment as below

kubectl create -f deploy         


        
6条回答
  •  执笔经年
    2020-12-20 12:58

    I used envsubst (https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html) for this. Create a deployment.yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: $NAME
      labels:
        app: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80
    

    Then:

    export NAME=my-test-nginx
    envsubst < deployment.yaml | kubectl apply -f -
    

    Not sure what OS are you using to run this. On macOS, envsubst installed like:

    brew install gettext
    brew link --force gettext 
    

提交回复
热议问题