Skip to content

Instantly share code, notes, and snippets.

View georgegoh's full-sized avatar

George Goh georgegoh

  • VMware
  • Singapore
View GitHub Profile
@georgegoh
georgegoh / gist:24d0dc5c56e596a573d6af96596dc5e2
Created September 30, 2021 02:28
Get roles with rules using PSP with the name defined in the env var $PSP
kubectl get role -A -o json | jq '.items[] | . as $role | .rules[] | .resources | if any(. == "podsecuritypolicies") then $role else empty end' \
| jq --arg psp $PSP 'try . as $role | .rules[] | .resourceNames | if any(. == $PSP) then $role else empty end'
kubectl get psp -o json | jq -r '.items[] | if .spec.privileged or .spec.allowPrivilegeEscalation then .metadata.name else empty end'
@georgegoh
georgegoh / gist:d3ccd5662a3709b179a585d488cec012
Created July 23, 2021 02:03
vSphere w/ Tanzu comes with default PSPs. This gist allows any service account to run pods with restricted privileges by using the supplied `vmware-system-restricted` policy.
# (vSphere w/ Tanzu) allow any service account to run pods with restricted privileges.
kubectl create clusterrolebinding all:psp:restricted \
--clusterrole=psp:vmware-system-restricted \
--group=system:serviceaccounts
ETCDCTL_API=3 /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/18/fs/usr/local/bin/etcdctl \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key \
get /registry/secrets/default/secret1
@georgegoh
georgegoh / get_images.sh
Last active April 10, 2021 05:17
Extract image names from a tkg-extensions values.yaml
yq e '.. | select(has("repository")) | .repository + "/" + .name + ":" + .tag' values.yaml
@georgegoh
georgegoh / gist:044da30fb053110c755246ea330a75b2
Created March 2, 2021 07:25
Get IP addresses of all nodes in a kubernetes cluster
kubectl get nodes -o=go-template --template='{{range .items}}{{range .status.addresses}}{{if eq .type "ExternalIP" }}{{.address}}{{printf "\n"}}{{end}}{{end}}{{end}}'
@georgegoh
georgegoh / debug-pod.yaml
Last active March 3, 2021 06:49
Run a deploy pod - to attach `kubectl attach -i debug`
apiVersion: v1
kind: Pod
metadata:
labels:
run: debug
name: debug
namespace: default
spec:
containers:
- args:
@georgegoh
georgegoh / clusterctl-config.sh
Created March 10, 2020 12:30
Creating YAML file for cluster
clusterctl --config=clusterctl.yaml config cluster k8s-quickstart \
--infrastructure vsphere:v0.6.0-rc.2 \
--kubernetes-version v1.17.3 \
--control-plane-machine-count 1 --worker-machine-count 3 > cluster.yaml
@georgegoh
georgegoh / clusterctl.yaml
Created March 10, 2020 12:26
Config for clusterctl (cluster-api v0.3.0)
## -- Controller settings -- ##
VSPHERE_USERNAME: "k8s-admin@vsphere.local". # The username used to access the remote vSphere endpoint
VSPHERE_PASSWORD: "Demo123!" # The password used to access the remote vSphere endpoint
## -- Required workload cluster default settings -- ##
VSPHERE_SERVER: "vcenter.lab.spodon.com" # The vCenter server IP or FQDN
VSPHERE_DATACENTER: "Datacenter" # The vSphere datacenter to deploy the management cluster on
VSPHERE_DATASTORE: "ssd01" # The vSphere datastore to deploy the management cluster on
VSPHERE_NETWORK: "VM Network" # The VM network to deploy the management cluster on
VSPHERE_RESOURCE_POOL: "*/Resources" # The vSphere resource pool for your VMs
@georgegoh
georgegoh / clusterctl-kind-bootstrap.sh
Created March 10, 2020 12:20
First step in creating a kind cluster
kind create cluster --name=clusterapi
clusterctl --config=clusterctl.yaml init \
--core cluster-api:v0.3.0-rc.3 \
--bootstrap kubeadm:v0.3.0-rc.3 \
--control-plane kubeadm:v0.3.0-rc.3 \
--infrastructure vsphere:v0.6.0-rc.2