|
| 1 | +--- |
| 2 | +title: "Using KubernetesLocalProcessConfig.yaml for additional configuration with for Local Process with Kubernetes" |
| 3 | +services: azure-dev-spaces |
| 4 | +ms.date: 07/28/2020 |
| 5 | +ms.topic: "conceptual" |
| 6 | +description: "Describes the additional configuration options for Local Process with Kubernetes using KubernetesLocalProcessConfig.yaml" |
| 7 | +keywords: "Local Process with Kubernetes, Azure Dev Spaces, Dev Spaces, Docker, Kubernetes, Azure, AKS, Azure Kubernetes Service, containers" |
| 8 | +monikerRange: ">=vs-2019" |
| 9 | +author: ghogen |
| 10 | +ms.author: ghogen |
| 11 | +manager: jillfra |
| 12 | +--- |
| 13 | + |
| 14 | +# Configure Local Process with Kubernetes |
| 15 | + |
| 16 | +The `KubernetesLocalProcessConfig.yaml` file allows you to replicate environment variables and mounted files available to your pods in your AKS cluster. You can specify the following actions in a `KubernetesLocalProcessConfig.yaml` file: |
| 17 | + |
| 18 | +* Download a volume and set the path to that volume as an environment variable. |
| 19 | +* Make a service running on your cluster available to processes running on your development computer. |
| 20 | +* Create an environment variable with a constant value. |
| 21 | + |
| 22 | +A default `KubernetesLocalProcessConfig.yaml` file is not created automatically so you must manually create the file at the root of your project. |
| 23 | + |
| 24 | +## Download a volume |
| 25 | + |
| 26 | +Under *env*, specify a *name* and *value* for each volume you want to download. The *name* is the environment variable that will be used on your development computer. The *value* is the name of the volume and a path on your development computer. The value for *value* takes the form *$(volumeMounts:VOLUME_NAME)/PATH/TO/FILES*. |
| 27 | + |
| 28 | +For example: |
| 29 | + |
| 30 | +```yaml |
| 31 | +version: 0.1 |
| 32 | +env: |
| 33 | + - name: ALLOW_LIST_PATH |
| 34 | + value: $(volumeMounts:allow-list)/allow-list |
| 35 | +``` |
| 36 | +
|
| 37 | +The above example downloads the *allow-list* volume from the container and sets that location plus the path to the environment variable *ALLOW_LIST_PATH*. The default behavior is to download the files to the path you specify under a temporary directory on your development computer. In the above example, *ALLOW_LIST_PATH* is set to `/TEMPORARY_DIR/allow-list`. |
| 38 | + |
| 39 | +> [!NOTE] |
| 40 | +> Downloading a volume will download the entire contents of that volume regardless of the path you set. The path is only used to set the environment variable for use on the development computer. Adding */allow-list* or */path/to/files* to the end of the token doesn't actually affect where the volume is persisted. The environment variable is just a convenience in case your app needs a reference to a specific file inside that volume. |
| 41 | + |
| 42 | +You also have the option to specify a location to download the volume mount on your development computer instead of using a temporary directory. Under *volumeMounts*, specify a *name* and *localPath* for each specific location. The *name* is the volume name you want to match, and *localPath* is the absolute path on your development computer. For example: |
| 43 | + |
| 44 | +```yaml |
| 45 | +version: 0.1 |
| 46 | +volumeMounts: |
| 47 | + - name: default-token-* |
| 48 | + localPath: /var/run/secrets/kubernetes.io/serviceaccount |
| 49 | +env: |
| 50 | + - name: KUBERNETES_IN_CLUSTER_CONFIG_OVERRIDE |
| 51 | + value: $(volumeMounts:default-token-*) |
| 52 | +``` |
| 53 | + |
| 54 | +The above example uses the entry in *env* to download a volume matching *default-token-\**, such as *default-token-1111* or *default-token-1234-5678-90abcdef*. In cases where multiple volumes match, the first matching volume is used. All files are downloaded to `/var/run/secrets/kubernetes.io/serviceaccount` on your development computer using the entry in *volumeMounts*. The *KUBERNETES_IN_CLUSTER_CONFIG_OVERRIDE* environment variable is set to `/var/run/secrets/kubernetes.io/serviceaccount`. |
| 55 | + |
| 56 | +## Make a service available |
| 57 | + |
| 58 | +Under *env*, specify a *name* and *value* for each service you want to make available on your development computer. The *name* is the environment variable that will be used on your development computer. The *value* is the name of the service from your cluster and a path. The value for *value* takes the form *$(services:SERVICE_NAME)/PATH*. |
| 59 | + |
| 60 | +For example: |
| 61 | + |
| 62 | +```yaml |
| 63 | +version: 0.1 |
| 64 | +env: |
| 65 | + - name: MYAPP1_SERVICE_HOST |
| 66 | + value: $(services:myapp1)/api/v1/ |
| 67 | +``` |
| 68 | + |
| 69 | +The above example makes the *myapp1* service available to your development computer and the *MYAPP1_SERVICE_HOST* environment variable is set to the local IP address of the *myapp1* service with the `/api/v1` path (that is, `127.1.1.4/api/v1`). The *myapp1* service is accessible using the environment variable, *myapp1*, or *myapp1.svc.cluster.local*. |
| 70 | + |
| 71 | +> [!NOTE] |
| 72 | +> Making a service available on your development computer will make the entire service available regardless of the path you set. The path is only used to set the environment variable for use on the development computer. |
| 73 | +You can also make a service from a specific Kubernetes namespace available using *$(services:SERVICE_NAME.NAMESPACE_NAME)*. For example: |
| 74 | + |
| 75 | +```yaml |
| 76 | +version: 0.1 |
| 77 | +env: |
| 78 | + - name: MYAPP2_SERVICE_HOST |
| 79 | + value: $(services:myapp2.mynamespace) |
| 80 | +``` |
| 81 | + |
| 82 | +The above example makes the *myapp2* from the *mynamespace* namespace available on your development computer and sets the *MYAPP2_SERVICE_HOST* environment variable to the local IP address of the *myapp2* from the *mynamespace* namespace. |
| 83 | + |
| 84 | +## Create an environment variable with a constant value |
| 85 | + |
| 86 | +Under *env*, specify a *name* and *value* for each environment variable you want to create on your development computer. The *name* is the environment variable that will be used on your development computer and the *value* is the value. For example: |
| 87 | + |
| 88 | +```yaml |
| 89 | +version: 0.1 |
| 90 | +env: |
| 91 | + - name: DEBUG_MODE |
| 92 | + value: "true" |
| 93 | +``` |
| 94 | + |
| 95 | +The above example creates an environment variable named *DEBUG_MODE* with a value of *true*. |
| 96 | + |
| 97 | +## Example KubernetesLocalProcessConfig.yaml |
| 98 | + |
| 99 | +Here is an example of a complete `KubernetesLocalProcessConfig.yaml` file: |
| 100 | + |
| 101 | +```yaml |
| 102 | +version: 0.1 |
| 103 | +volumeMounts: |
| 104 | + - name: default-token-* |
| 105 | + localPath: /var/run/secrets/kubernetes.io/serviceaccount |
| 106 | +env: |
| 107 | + - name: KUBERNETES_IN_CLUSTER_CONFIG_OVERRIDE |
| 108 | + value: $(volumeMounts:default-token-*) |
| 109 | + - name: ALLOW_LIST_PATH |
| 110 | + value: $(volumeMounts:allow-list)/allow-list |
| 111 | + - name: MYAPP1_SERVICE_HOST |
| 112 | + value: $(services:myapp1)/api/v1/ |
| 113 | + - name: MYAPP2_SERVICE_HOST |
| 114 | + value: $(services:myapp2.mynamespace) |
| 115 | + - name: DEBUG_MODE |
| 116 | + value: "true" |
| 117 | +``` |
| 118 | + |
| 119 | +## Next Steps |
| 120 | + |
| 121 | +To get started using Local Process with Kubernetes to connect to your local development computer to your cluster, see [Use Local Process with Kubernetes with Visual Studio Code][local-process-kubernetes-vs-code] and [Use Local Process with Kubernetes with Visual Studio][local-process-kubernetes-vs]. |
| 122 | + |
| 123 | +[local-process-kubernetes-vs-code]: https://code.visualstudio.com/docs/containers/local-process-kubernetes |
| 124 | +[local-process-kubernetes-vs]: local-process-kubernetes.md |
0 commit comments