how to pass environment variable in kubectl deployment?

前端 未结 6 495
失恋的感觉
失恋的感觉 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:59

    You cannot pass variables to "kubectl create -f". YAML files should be complete manifests without variables. Also you cannot use "-l" flag to "kubectl create -f".

    If you want to pass environment variables to pod you should do like that:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
      labels:
        app: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            env:
            - name: MY_VAT
              value: MY_VALUE
            ports:
            - containerPort: 80
    

    Read more here: https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/

提交回复
热议问题