1. 只有容器的情况下:

    apiVersion: v1
    kind: Pod
    metadata:
      name: envpod
    spec:
      containers:
        - name: test-container
          #image: k8s.gcr.io/busybox
          image: busybox
          command: [ "sh", "-c"]
          args:
          - while true; do
              echo -en '\n';
              printenv MY_NAME;
              sleep 10;
            done;
          env:
            - name: MY_NAME
              value: name1
      restartPolicy: Never
    

    kubectl edit po envpod 更改了MY_NAME这个环境变量后
    1. pod不会重启
    2. 里面的程序也感知不到环境变量的变化

  2. ReplicaController

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: env-rc
    spec:
      replicas: 1
      selector:
        app: env-rc-pod
      template:
        metadata:
          labels:
            app: env-rc-pod
        spec:
          containers:
          - name: test-container
            image: busybox
            command: [ "sh", "-c"]
            args:
            - while true; do
                echo -en '\n';
                printenv MY_NAME;
                sleep 10;
              done;
            env:
              - name: MY_NAME
                value: name1
    

    kubectl edit rc env-rc 更改了MY_NAME这个环境变量后
    1. rc不会重启
    2. pod也不会有什么变化
    3. 里面的程序也感知不到环境变量的变化

  3. ReplicaSet

    apiVersion: apps/v1
    kind: ReplicaSet
    metadata:
      name: env-rs
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: env-rs-pod
      template:
        metadata:
          labels:
            app: env-rs-pod
        spec:
          containers:
          - name: test-container
            image: busybox
            command: [ "sh", "-c"]
            args:
            - while true; do
                echo -en '\n';
                printenv MY_NAME;
                sleep 10;
              done;
            env:
              - name: MY_NAME
                value: name1
    

    kubectl edit rs env-rs 更改了MY_NAME这个环境变量后
    1. rs不会重启
    2. pod也不会有什么变化
    3. 里面的程序也感知不到环境变量的变化

  4. Deployment

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: env-deploy
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: env-deploy-pod
      template:
        metadata:
          labels:
            app: env-deploy-pod
        spec:
          containers:
          - name: test-container
            image: busybox
            command: [ "sh", "-c"]
            args:
            - while true; do
                echo -en '\n';
                printenv MY_NAME;
                sleep 10;
              done;
            env:
              - name: MY_NAME
                value: name1
    

    kubectl edit deploy env-deploy 更改了MY_NAME这个环境变量后
    1. deploy 不会有什么变化
    2. 对应的pod会进行rolling update
    3. 新创建出来的pod使用新的环境变量
    4. 多出一个rs:

      	root@ubuntu18:~/k8s/env# k get rs
      	NAME                    DESIRED   CURRENT   READY   AGE
      	env-deploy-5b79f7f777   0         0         0       29m
      	```
    
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐