Skip to content

Instantly share code, notes, and snippets.

@berinle
Last active April 25, 2024 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berinle/abb1b63187c5e1407f480e06bd602f71 to your computer and use it in GitHub Desktop.
Save berinle/abb1b63187c5e1407f480e06bd602f71 to your computer and use it in GitHub Desktop.
Steps to apply gatekeeper to an existing TKG guest cluster

login to your guest cluster e.g.

❯ kubectl vsphere login --server=SERVER_IP --tanzu-kubernetes-cluster-namespace=NAMESPACE --tanzu-kubernetes-cluster-name=CLUSTER_NAME -u=administrator@vsphere.local --insecure-skip-tls-verify

run the gatekeeper.yaml (located in the gatekeeper directory of the cloned/downloaded project)

kubectl apply -f gatekeeper.yaml

verify gatekeeper pods are all running

❯ kubectl get po -n gatekeeper-system
NAME                                             READY   STATUS    RESTARTS      AGE
gatekeeper-audit-6d588687dd-rbz2d                1/1     Running   1 (48s ago)   52s
gatekeeper-controller-manager-5d7465bfb7-btj7h   1/1     Running   0             52s
gatekeeper-controller-manager-5d7465bfb7-m927k   1/1     Running   0             52s
gatekeeper-controller-manager-5d7465bfb7-nnszk   1/1     Running   0             52s

if the pods are all running, you are good. If you hit docker rate limit issues, you will need to relocate the openpolicyagent/gatekeeper to your local harbor registry and run the following to reference your copy (instead of dockerhub's copy)

# ensure you edit kustomization.yaml to point to your own image https://github.com/papivot/argocd-gitops-tanzu/blob/main/gatekeeper/kustomization.yaml#L10
❯ kubectl apply -f kustomization.yaml

apply the mutating psa

❯ kubectl apply -f mutation-psa-policy.yaml

label all existing namespaces (as gatekeeper will only apply to newly created namespaces)

kubectl label --overwrite ns --all pod-security.kubernetes.io/enforce=privileged

Testing

## create a new namespace
$ kubectl create ns demo
$ kubectl get ns demo -oyaml (you should see `pod-security.kubernetes.io/enforce: privileged` as part of the namespace labels)
$ kubectl run nginx --image=nginx:1.25.1 -n demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment