Exercise 6.1: Set SecurityContext for a Pod and Container
cat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: ubuntu spec: containers: - name: ubuntu image: youngwjung/ubuntu-with-user command: [ "sleep" ] args: [ "infinity" ] EOFkubectl get pod ubuntukubectl exec -it ubuntu -- whoamikubectl exec -it ubuntu -- apt updatekubectl delete pod ubuntucat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: ubuntu spec: securityContext: runAsUser: 1000 containers: - name: ubuntu image: youngwjung/ubuntu-with-user command: [ "sleep" ] args: [ "infinity" ] securityContext: runAsUser: 2000 EOFkubectl exec -it ubuntu -- /bin/bashidapt updatesuapt updateexitexitkubectl delete pod ubuntucat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: ubuntu spec: securityContext: runAsUser: 1000 containers: - name: ubuntu image: youngwjung/ubuntu-with-user command: [ "sleep" ] args: [ "infinity" ] securityContext: runAsUser: 2000 allowPrivilegeEscalation: false EOFkubectl exec -it ubuntu -- /bin/bashsuexitkubectl delete pod ubuntucat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: alpine spec: containers: - name: alpine image: praqma/network-multitool command: [ "sleep" ] args: [ "infinity" ] EOFkubectl exec -it alpine -- ping -c 3 www.google.comkubectl exec -it alpine -- date -s "11:11:11"kubectl delete pod alpinecat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: alpine spec: containers: - name: alpine image: praqma/network-multitool command: [ "sleep" ] args: [ "infinity" ] securityContext: capabilities: add: ["NET_RAW", "SYS_TIME"] EOFkubectl exec -it alpine -- ping -c 3 www.google.comkubectl exec -it alpine -- date -s "11:11:11"kubectl delete pod alpine
Last updated