Skip to content

Commit

Permalink
Merge pull request #1 from astrieanna/patch-1
Browse files Browse the repository at this point in the history
Add example of using secrets on windows
  • Loading branch information
PatrickLang authored Nov 7, 2018
2 parents e984068 + b26bb73 commit ee898b2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
24 changes: 23 additions & 1 deletion content/en/docs/getting-started-guides/windows/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,29 @@ Sample: stop web service to trigger restart

#### Handling secrets

Sample: database connection string
1. Create a secret by following the [standard directions](https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-secret)

2. Configure your pod to receive the secret via an environment variable.
{{< codenew file="windows/secret-pod.yaml" >}}

3. Deploy the pod and verify that it is running:
```bash
kubectl create -f https://k8s.io/docs/getting-started-guides/windows/secret-pod.yaml
kubectl get pod secret-envars-test-pod
```
4. Open a shell into the container running the pod:
```bash
kubectl exec -it secret-envars-test-pod -- powershell
```
5. See that the secret is in the environment variable:
```powershell
echo $env:SECRET_USERNAME $env:SECRET_PASSWORD
```
You should see the output:
```
my-app
39528$vdg7Jb
```

### Deploying a stateful application

Expand Down
43 changes: 18 additions & 25 deletions content/en/examples/windows/secret-pod.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
username: YWRtaW4=
password: MWYyZDFlMmU2N2Rm

---

apiVersion: v1
kind: Pod
metadata:
name: my-secret-pod
name: secret-envars-test-pod
spec:
containers:
- name: my-secret-pod
image: microsoft/windowsservercore:1709
- name: envars-test-container
image: microsoft/windowsservercore:latest
imagePullPolicy: Never
command:
- ping
- -t
- localhost
env:
- name: USERNAME
valueFrom:
secretKeyRef:
name: mysecret
key: username
- name: PASSWORD
valueFrom:
secretKeyRef:
name: mysecret
key: password
nodeSelector:
beta.kubernetes.io/os: windows
- name: SECRET_USERNAME
valueFrom:
secretKeyRef:
name: test-secret
key: username
- name: SECRET_PASSWORD
valueFrom:
secretKeyRef:
name: test-secret
key: password

0 comments on commit ee898b2

Please sign in to comment.