how to pass environment variable in kubectl deployment?

前端 未结 6 479
失恋的感觉
失恋的感觉 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 13:07

    File: ./deployment.yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: MYAPP
      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
    

    File: ./service.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: MYAPP
      labels:
        app: nginx
    spec:
      type: ClusterIP
      ports:
      - port: 80
      selector:
        app: nginx
    

    File: ./kustomization.yaml

    resources:
    - deployment.yaml
    - service.yaml
    

    If you're using https://kustomize.io/, you can do this trick in a CI:

    sh '( echo "images:" ; echo "  - name: $IMAGE" ; echo "    newTag: $VERSION" ) >> ./kustomization.yaml'
    sh "kubectl apply --kustomize ."
    

提交回复
热议问题