Skip to content

Instantly share code, notes, and snippets.

@ams0
Last active May 1, 2019 11:14
Show Gist options
  • Select an option

  • Save ams0/ee0a6c2c55875d88df037da0212eab59 to your computer and use it in GitHub Desktop.

Select an option

Save ams0/ee0a6c2c55875d88df037da0212eab59 to your computer and use it in GitHub Desktop.
Create a SA and a binding to the psp:privileged role, then creates a deployment with hostmount

PSP are evaluated only when a pod is created directly; when a Deployment or a Daemonset creates a pod, does so using the default serviceaccount of that namespace. Thus, you need to give that SA (or a purposefully create SA) a binding to the appropriate PSP.

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-privileged
spec:
selector:
matchLabels:
name: nginx-privileged
template:
metadata:
labels:
name: nginx-privileged
spec:
containers:
- name: nginx-privileged
image: nginx:1.14.2
securityContext:
privileged: true
volumeMounts:
- name: root-volume
mountPath: /mnt/rootnode
serviceAccountName: default-privileged
volumes:
- hostPath:
path: /
name: root-volume
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: default
name: default-privileged
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: default:privileged
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: psp:privileged
subjects:
- kind: ServiceAccount
namespace: default
name: default-privileged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment