How to create Kubernetes Namespace if it does not Exist?

i wouldn’t go for any other solution except the following code snippet: kubernetes 1.19 and above (included) kubectl create namespace <add-namespace-here> –dry-run=client -o yaml | kubectl apply -f – kubernetes 1.18 and below (included) kubectl create namespace <add-namespace-here> –dry-run -o yaml | kubectl apply -f – it creates a namespace in dry-run and outputs it … Read more

Can I connect one service account to multiple namespaces in Kubernetes?

You can simply reference a ServiceAccount from another namespace in the RoleBinding: apiVersion: rbac.authorization.k8s.io/v1beta1 kind: Role metadata: name: pod-reader namespace: ns2 rules: – apiGroups: [“”] resources: [“pods”] verbs: [“get”, “list”, “watch”] — apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: pod-reader-from-ns1 namespace: ns2 roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: pod-reader subjects: – kind: ServiceAccount name: ns1-service-account namespace: … Read more

How to force delete a Kubernetes Namespace?

The kubectl proxy try is almost correct, but not quite. It’s possible using JSON instead of YAML does the trick, but I’m not certain. The JSON with an empty finalizers list: ~$ cat ns.json { “kind”: “Namespace”, “apiVersion”: “v1”, “metadata”: { “name”: “delete-me” }, “spec”: { “finalizers”: [] } } Use curl to PUT the … Read more