Interacting with Kubernetes Pods using microk8s
microk8s kubectl logs <pod-name>
- View the logs of a specific pod.
microk8s kubectl exec -it <pod-name> — /bin/sh
- Start an interactive shell inside a pod.
microk8s kubectl exec envar-demo — printenv
- Execute the
printenv
command inside the pod namedenvar-demo
using MicroK8s.
Managing Deployments
microk8s kubectl create deployment <deployment-name> — image=<image-name>
- Create a new deployment.
microk8s kubectl expose deployment <deployment-name> — type=NodePort — port=<port>
- Expose a deployment as a NodePort service.
microk8s kubectl scale deployment <deployment-name> — replicas=<desired-replicas>
- Scale the number of replicas for a deployment.
microk8s kubectl delete pod <pod-name>
- Delete a specific pod.
microk8s kubectl delete deployment <deployment-name>
- Delete a deployment.
Configuration and Resources
microk8s kubectl apply -f <filename>
- Apply a configuration file to the cluster.
microk8s kubectl get pv
- List persistent volumes.
microk8s kubectl get pvc
- List persistent volume claims.
microk8s kubectl get configmaps
- List config maps.
microk8s kubectl get secrets
- List secrets.
microk8s kubectl get ingress
- List ingress resources.
Cluster Management and Troubleshooting
microk8s kubectl describe node <node-name>
- Get detailed information about a specific node.
microk8s kubectl proxy
- Start a proxy to access the Kubernetes API server.
microk8s kubectl get events
- List cluster events.
microk8s kubectl rollout history deployment <deployment-name>
- View the rollout history of a deployment.
microk8s kubectl rollout undo deployment <deployment-name> — to-revision=<revision>
- Rollback a deployment to a specific revision.
Additional Tips
microk8s kubectl get all
- List all resources in the current namespace.
microk8s kubectl exec -it <pod-name> — /bin/sh -n <namespace>
- Start an interactive shell inside a pod in a specific namespace.
microk8s kubectl port-forward <pod-name> <local-port>:<remote-port>
- Forward ports from a pod to your local machine.
microk8s kubectl label <resource> <resource-name> <key>=<value>
- Add a label to a resource.
microk8s kubectl exec envar-demo — printenv
- Execute the
printenv
command inside the pod namedenvar-demo
using MicroK8s.
These kubectl
and MicroK8s commands provide a comprehensive set of tools for managing, troubleshooting, and interacting with Kubernetes clusters. Experimenting with these commands in different scenarios will contribute to a deeper understanding of Kubernetes orchestration and enhance your proficiency in cluster management.