Pass variable to K8S

1) Hard code in code base 

2) add in deployment as environment variable 

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: myapp
  namespace: myapp
spec:
  template:
    spec:
      containers:
      - image: myapp-docker-image
        name: django
        env:
        - name: DJANGO_ALLOWED_HOSTS
          value: "['myapp.K8S_INGRESS_ROOT_DOMAIN_NAME']"

 3) add in config map

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: myapp
  namespace: myapp
spec:
  template:
    spec:
      containers:
      - image: myapp-docker-image
        name: django
        env:
        - name: DJANGO_MYAPP_SOME_API_URI    // the variable want to replace
          valueFrom:
          configMapKeyRef:
            name: app-override-env      // config map which includes the key DJANGO....
            key: DJANGO_MYAPP_SOME_API_URI   // the key of the variable in the config map
            optional: true  // If you removed optional: true, and the config map did not exist in the deployment repository or did not contain the key DJANGO_MYAPP_SOME_API_URI, the deployment pipeline would succeed, but the deployment pods would all fail to start.
        ...

 4) Secrect 

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: myapp
  namespace: myapp
spec:
  replicas: 3
  revisionHistoryLimit: 2
  template:
    metadata:
      labels:
        app: django
    spec:
      containers:
      - image: image-url
        name: django
        env:
        - name: DJANGO_DATABASES
          valueFrom:
            secretKeyRef:
              name: quartz
              key: django.databases

 

posted @ 2021-02-23 06:32  anyu686  阅读(41)  评论(0编辑  收藏  举报