Change:
This is a Feature Request <!-- Please only use this template for submitting feature/enhancement requests --<!-- See for guidance on writing an actionable issue description. --What would you like to be <!-- Describe as precisely as possible how this feature/enhancement should work from the user perspective. What should be changed, etc. --Why is this needed If the environment variables started by the pod are cyclically dependent and mutually referenced, the resulting environment variable values ​​will not be what we expected. At present, there is no detailed description about this in the official document, it is recommended to reopen a page to describe it in detail Comments <!-- Any additional related comments that might help. Drawings/mockups would be extremely helpful (if required). --
/kind feature
/assign

Discussion:
<ins> --- title: Define Dependent Environment Variables content_type: task weight: 20 --- <!-- overview --> This page shows how to define dependent environment variables for a container in a Kubernetes Pod. ## {{% heading "prerequisites" %}} {{< include "task-tutorial-prereqs.md" >}} <!-- steps --> ## Define an environment dependent variable for a container When you create a Pod, you can set dependent environment variables for the containers that run in the Pod. To set dependent environment variables, you can use $(VAR_NAME) in the `value` of `env` in the configuration file. In this exercise, you create a Pod that runs one container. The configuration file for the Pod defines an dependent environment variable with common usage defined. Here is the configuration manifest for the Pod: {{< codenew file="pods/inject/dependent-envars.yaml" >}} 1. Create a Pod based on that manifest: ```shell kubectl apply -f https://k8s.io/examples/pods/inject/dependent-envars.yaml ``` ``` pod/dependent-envars-demo created ``` 2. List the running Pods: ```shell kubectl get pods dependent-envars-demo ``` ``` NAME                      READY     STATUS    RESTARTS   AGE dependent-envars-demo     1/1       Running   0          9s ``` 3. Check the logs for the container running in your Pod: ```shell kubectl logs pod/dependent-envars-demo ``` ``` UNCHANGED_REFERENCE=$(PROTOCOL)://172.17.0.1:80 SERVICE_ADDRESS=https://172.17.0.1:80 ESCAPED_REFERENCE=$(PROTOCOL)://172.17.0.1:80 ``` As shown above, you have defined the correct dependency reference of `SERVICE_ADDRESS`, bad dependency reference of `UNCHANGED_REFERENCE` and skip dependent references of `ESCAPED_REFERENCE`. When an environment variable is already defined when being referenced, the reference can be correctly resolved, such as in the `SERVICE_ADDRESS` case. When the environment variable is undefined or only includes some variables, the undefined environment variable is treated as a normal string, such as `UNCHANGED_REFERENCE`. Note that incorrectly parsed environment variables, in general, will not block the container from starting. The `$(VAR_NAME)` syntax can be escaped with a double `$`, ie: `$$(VAR_NAME)`. Escaped references are never expanded, regardless of whether the referenced variable is defined or not. This can be seen from the `ESCAPED_REFERENCE` case above. ## {{% heading "whatsnext" %}} * Learn more about [environment variables](/docs/tasks/inject-data-application/environment-variable-expose-pod-information/). * See [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core). </ins>

<ins> apiVersion: v1 kind: Pod metadata: name: dependent-envars-demo spec: containers: - name: dependent-envars-demo args: - while true; do echo -en 'n'; printf UNCHANGED_REFERENCE=$UNCHANGED_REFERENCE'n'; printf SERVICE_ADDRESS=$SERVICE_ADDRESS'n';printf ESCAPED_REFERENCE=$ESCAPED_REFERENCE'n'; sleep 30; done; command: - sh - -c image: busybox env: - name: SERVICE_PORT value: "80" - name: SERVICE_IP value: "172.17.0.1" - name: UNCHANGED_REFERENCE value: "$(PROTOCOL)://$(SERVICE_IP):$(SERVICE_PORT)" - name: PROTOCOL value: "https" - name: SERVICE_ADDRESS value: "$(PROTOCOL)://$(SERVICE_IP):$(SERVICE_PORT)" - name: ESCAPED_REFERENCE value: "$$(PROTOCOL)://$(SERVICE_IP):$(SERVICE_PORT)" </ins>