# alias mk=minikube
minikube start
minikube stop
minikube delete
k create namespace <name>
kaf <path> -n <namespace>
kdelf <path> -n <namespace>
kg{p|s|ns..} -n <namespace>
kd{p|s|ns..} -n <namespace>
--selector app=demo
-l app=demo
k port-forward <pod> <local>:<pod> -n <namespace>
# generate resource manifests
kubectl run demo --image=<image> --dry-run -o yaml
# export existing resources
kubectl get deployments <deployment> -o yaml -n <namespace>
k diff -f <path>
# log pod
k logs --tail 20 <pod> -n <namespace>
# get shell from pod's container
kubectl exec -it [-c <container>] <pod> /bin/sh
kubectl run -n <namespace> busybox --image=busybox:1.28 --rm -it --restart=Never /bin/ash
It can be particularly useful to view the Kubernetes API server’s logs; for example, if you have RBAC permission errors, they’ll show up here. If you have access to your master nodes,you can find the
kube-apiserver
Pod in thekube-system
namespace and usekubectl logs
to see its output.If you’re using a managed service like GKE, where the master nodes are not visible toyou, check your provider’s documentation to see how to find the control plane logs(for example, on GKE they’ll be visible in the Stackdriver Logs Viewer).
For more sophisticated log watching, you may want to use a dedicated tool like
Stern
insteadCloud Native Devops with Kubernetes p.120
kubectx <context>
kubectx -
kubectx <NEW_NAME>=<context>
kubectx -d <context>
kubens <namespace>
kubens -
# get current context
k config current-context
# list contexts
k config get-contexts
# create or update context
k config set-context <context> --cluster <cluster> --namespace <namespace>
# switch context
k config use-context <context>