https://kubernetes.io/docs/reference/kubectl/cheatsheet/
List namespaces
kubectl get namespace
Create namespace
kubectl create namespaces <insert-some-namespace-name>
also, it can be created with a yml
apiVersion: v1
kind: Namespace
metadata:
name: <insert-namespace-name-here>
kubectl create -f ./my-namespace.yaml
Delete namespace
kubectl delete namespaces <insert-some-namespace-name>
Set namespace preference
kubectl config set-context --current --namespace=<insert-namespace-name-here>
# Validate it
kubectl config view --minify | grep namespace:
Get all Pods regardless namespace
kubectl get pods --all-namespaces
Get services
kubectl get svc -n <namespace>
kubectl exec -it <pod_name> bash -n <namespace>
Get Pods from namespace
kubectl get pods --namespace=<insert-namespace-name-here>
Get pods of current namespace
kubectl get pods --show-labels
get pods by namepsace
kubectl get pod -n <namespace>
kubectl get secrets -n <namespace>
kubectl get deployment -n <namespace>
kubectl port-forward svc/<service-name> <our-port>:<their-port> -n <namespace>
getting ingress
kubectl get ingress -n <namespace> <ingress-name> -o yaml > ingress.yaml
kubectl apply -f <file-yaml> -n <namespace>
attach terminal to a pod's log
kubectl logs -n <namespace> <pod-name> -f
attach terminal to a pod's so that we can run commands inside it
kubectl -n <namespace> exec -it <pod-name> bash
list deployed
helm list -n <namespace>
list cronjobs config
kubectl get cronjobs -n <nameslace>
review cron job
kubectl describe cronjob <name> -n <namespace>