-
Notifications
You must be signed in to change notification settings - Fork 483
/
Copy pathsecuritycontext-user.yaml
41 lines (41 loc) · 1.44 KB
/
securitycontext-user.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
# kubectl exec -it security-context-demo -c demo1 touch /data/demo/test.log
# kubectl exec -it security-context-demo -c demo1 -- ls -l /data/demo/test.log
# ,-----------
# | kubectl exec -it security-context-demo -- ls -l /data/demo/test.log
# | -rw-r--r-- 1 1000 2000 0 Sep 19 16:18 /data/demo/test.log
# `-----------
# kubectl exec -it security-context-demo -c demo2 touch /tmp/test.log
# kubectl exec -it security-context-demo -c demo2 -- ls -l /tmp/test.log
# ,-----------
# | kubectl exec -it security-context-demo -c demo2 -- ls -l /tmp/test.log
# | -rw-r--r-- 1 2000 root 0 Sep 19 16:38 /tmp/test.log
# `-----------
# https://cheatsheet.dennyzhang.com/kubernetes-yaml-templates
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo
spec:
securityContext:
runAsUser: 1000
fsGroup: 2000
volumes:
- name: sec-ctx-vol
emptyDir: {}
containers:
- name: demo1
image: gcr.io/google-samples/node-hello:1.0
volumeMounts:
- name: sec-ctx-vol
mountPath: /data/demo
securityContext:
allowPrivilegeEscalation: false
- name: demo2
image: busybox
args: [/bin/sh, -c,
'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done']
securityContext:
# configure security context at container level, instead of pod level
runAsUser: 2000
allowPrivilegeEscalation: false