A namespace is a logical parition inside k8s. it will create multiple teams and projects
Ex: Namespaces
frontend
bacckend
monitoring
network
Default Namespaces
Default namespace : used for when no namespace is specificed
kube-system : k8s componets will be runing on it (coreDNS, Kube-proxy…etc)
Kube-public: Publicly readable (rarely used)
kube-node-lease: node hartbeats (logs coolection)
basic commands:
# Create namespace
kubectl create ns dev
# get all namespace
kubectl get ns
# Delete namespace
Kubectl delete ns <namespace>
# Note when delete ns it will delete all configuire deploy on namespace
apiVersion: v1
kind: Namespace
metadata:
labels:
kubernetes.io/metadata.name: dev
name: dev
create pod with Sa kubectl apply -f deployment.yaml
Verify pod attached serviceAccount kubectl get pods -n demo <podName> -o yaml | grep serviceAccountName
# check get
kubectl auth can-i get pods \
--as=system:serviceaccount:demo:pod-read-sa -n demo
# check list
kubectl auth can-i list pods \
--as=system:serviceaccount:demo:pod-read-sa -n demo
# watch
kubectl auth can-i watch pods \
--as=system:serviceaccount:demo:pod-read-sa -n demo
# Check all once
kubectl auth can-i get,list,watch pods \
--as=system:serviceaccount:demo:pod-read-sa -n demo
TASK
Create namespace devops and serviceAccount devops-sa and create basic role qt-role and add perssions get,watch,list,update and create rolebinding qt-role-binding and finally attach service account deploy nginx and verify with above cmds.