Skip to content

Commit 3dbbf13

Browse files
Merge pull request #6924 from ghogen/kube2
Local Process with Kubernetes: yaml configuration
2 parents 43df639 + 3cb5b43 commit 3dbbf13

File tree

4 files changed

+150
-5
lines changed

4 files changed

+150
-5
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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

docs/containers/local-process-kubernetes.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
title: "Use Local Process with Kubernetes with Visual Studio (Preview)"
33
ms.technology: vs-azure
44
ms.date: 06/02/2020
5-
ms.topic: "conceptual"
5+
ms.topic: "how-to"
66
description: "Learn how to use Local Process with Kubernetes with Visual Studio to connect your development computer to a Kubernetes cluster"
77
keywords: "Local Process with Kubernetes, Azure Dev Spaces, Dev Spaces, Docker, Kubernetes, Azure, containers"
88
monikerRange: ">=vs-2019"
9+
ms.author: ghogen
10+
author: ghogen
11+
manager: jillfra
912
---
1013

1114
# Use Local Process with Kubernetes (Preview)
@@ -132,6 +135,10 @@ Remove the breakpoint by putting your cursor on line 26 in `BikesHelper.cs` and
132135
>
133136
> If Visual Studio abruptly ends the connection to the cluster or terminates, the service you are redirecting may not be restored to its original state before you connected with Local Process with Kubernetes. To fix this issue, see the [Troubleshooting guide][troubleshooting].
134137
138+
## Additional configuration
139+
140+
Local Process with Kubernetes can handle routing traffic and replicating environment variables without any additional configuration. If you need to download any files that are mounted to the container in your Kubernetes cluster, such as a ConfigMap file, you can create a `KubernetesLocalProcessConfig.yaml` to download those files to your development computer. For more information, see [Using KubernetesLocalProcessConfig.yaml for additional configuration with for Local Process with Kubernetes][kubernetesLocalProcessConfig-yaml].
141+
135142
## Using logging and diagnostics
136143

137144
You can find the diagnostic logs in `Azure Dev Spaces` directory in your [development computer's *TEMP* directory][azds-tmp-dir].
@@ -164,4 +171,5 @@ Learn how Local Process Kubernetes works.
164171
[supported-regions]: https://azure.microsoft.com/global-infrastructure/services/?products=kubernetes-service
165172
[troubleshooting]: /azure/dev-spaces/troubleshooting#fail-to-restore-original-configuration-of-deployment-on-cluster
166173
[visual-studio]: https://www.visualstudio.com/vs/
167-
[lpk-extension]: https://marketplace.visualstudio.com/items?itemName=ms-azuretools.mindaro
174+
[lpk-extension]: https://marketplace.visualstudio.com/items?itemName=ms-azuretools.mindaro
175+
[kubernetesLocalProcessConfig-yaml]: configure-local-process-with-kubernetes.md

docs/containers/overview-local-process-kubernetes.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ ms.topic: "conceptual"
66
description: "Describes the processes for using Local Process with Kubernetes to connect your development computer to your Kubernetes cluster"
77
keywords: "Local Process with Kubernetes, Docker, Kubernetes, Azure, containers"
88
monikerRange: ">=vs-2019"
9+
manager: jillfra
10+
author: ghogen
11+
ms.author: ghogen
912
---
1013

1114
# How Local Process with Kubernetes works
@@ -16,6 +19,9 @@ Local Process with Kubernetes avoids having to build and deploy your code to you
1619

1720
Local Process with Kubernetes redirects traffic between your connected Kubernetes cluster and your development computer. This traffic redirection allows code on your development computer and services running in your Kubernetes cluster to communicate as if they are in the same Kubernetes cluster. Local Process with Kubernetes also provides a way to replicate environment variables and mounted volumes available to pods in your Kubernetes cluster in your development computer. Providing access to environment variables and mounted volumes on your development computer allows you to quickly work on your code without having replicate those dependencies manually.
1821

22+
> [!WARNING]
23+
> Local Process for Kubernetes is intended for use in development and testing scenarios only. It is not intended or supported for use with production clusters or live services in active use.
24+
1925
## Using Local Process with Kubernetes
2026

2127
To use Local Process with Kubernetes in Visual Studio, you need [Visual Studio 2019][visual-studio] version 16.7 Preview 4 or greater running on Windows 10 with the *ASP.NET and web development* workload installed and the [Local Process Kubernetes Extension][lpk-extension] installed. When you use Local Process with Kubernetes to establish a connection to your Kubernetes cluster, you have the option of redirecting all traffic to and from an existing pod in the cluster to your development computer.
@@ -35,6 +41,12 @@ When Local Process with Kubernetes establishes a connection to your cluster, it:
3541

3642
After you establish a connection to your cluster, you can run and debug code natively on your computer, without containerization, and the code can directly interact with the rest of your cluster. Any network traffic the remote agent receives is redirected to the local port specified during the connection so your natively running code can accept and process that traffic. The environment variables, volumes, and secrets from your cluster are made available to code running on your development computer. Also, due to the hosts file entries and port forwarding added to your developer computer by Local Process with Kubernetes, your code can send network traffic to services running on your cluster using the service names from your cluster, and that traffic gets forwarded to the services that are running in your cluster. Traffic is routed between your development computer and your cluster the entire time you're connected.
3743

44+
In addition, Local Process with Kubernetes provides a way to replicate environment variables and mounted files available to pods in your cluster on your development computer through the `KubernetesLocalProcessConfig.yaml` file. You can also use this file to create new environment variables and volume mounts.
45+
46+
## Additional configuration with KubernetesLocalProcessConfig.yaml
47+
48+
The `KubernetesLocalProcessConfig.yaml` file allows you to replicate environment variables and mounted files available to your pods in your cluster. For more information on the additional configuration options, see [Configure Local Process with Kubernetes][using-config-yaml].
49+
3850
## Using routing capabilities for developing in isolation
3951

4052
By default, Local Process with Kubernetes redirects all traffic for a service to your development computer. You also have the option to use routing capabilities to only redirect requests to a service originating from a subdomain to your development computer. These routing capabilities allow you to use Local Process with Kubernetes to develop in isolation and avoid disrupting other traffic in your cluster.
@@ -103,4 +115,5 @@ To get started using Local Process with Kubernetes to connect to your local deve
103115
[local-process-kubernetes-vs]: local-process-kubernetes.md
104116
[kubectl-port-forward]: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#port-forward
105117
[visual-studio]: https://visualstudio.microsoft.com/downloads/
106-
[lpk-extension]: https://marketplace.visualstudio.com/items?itemName=ms-azuretools.mindaro
118+
[lpk-extension]: https://marketplace.visualstudio.com/items?itemName=ms-azuretools.mindaro
119+
[using-config-yaml]: configure-local-process-with-kubernetes.md

docs/containers/toc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
href: container-tools.md
1212
- name: React.js Single-page App in a Container
1313
href: container-tools-react.md
14-
- name: Kubernetes development
15-
href: local-process-kubernetes.md
1614
- name: Tutorials
1715
expanded: true
1816
items:
@@ -54,3 +52,5 @@
5452
href: local-process-kubernetes.md
5553
- name: How Local Process with Kubernetes works (Preview)
5654
href: overview-local-process-kubernetes.md
55+
- name: Configure Local Process with Kubernetes
56+
href: configure-local-process-with-kubernetes.md

0 commit comments

Comments
 (0)