🌟 Introduction to Kubernetes
Kubernetes, often abbreviated as K8s, is an open-source platform designed to automate the deployment, scaling, and operation of application containers. It provides a framework to run distributed systems resiliently. This documentation provides a basic introduction and commands to get started with Kubernetes for beginners.
📚 Basic Concepts
1. Pod
- The smallest and simplest Kubernetes object. A pod represents a single instance of a running process in your cluster.
2. Service
- A way to expose an application running on a set of Pods as a network service.
3. Deployment
- Manages a set of identical pods. Used to scale up or down and update pods systematically.
4. Namespace
- A way to divide cluster resources between multiple users.
🛠️ Kubernetes Commands
Cluster Setup
-
Check Cluster Information
kubectl cluster-info
-
Get Nodes in the Cluster
kubectl get nodes
Working with Namespaces
-
List All Namespaces
kubectl get namespaces
-
Create a New Namespace
kubectl create namespace <namespace-name>
-
Delete a Namespace
kubectl delete namespace <namespace-name>
Pods
-
List All Pods
kubectl get pods
-
Get Pod Details
kubectl describe pod <pod-name>
-
Delete a Pod
kubectl delete pod <pod-name>
Deployments
-
List All Deployments
kubectl get deployments
-
Create a Deployment
kubectl create deployment <deployment-name> --image=<image-name>
-
Scale a Deployment
kubectl scale deployment <deployment-name> --replicas=<number-of-replicas>
-
Update a Deployment
kubectl set image deployment/<deployment-name> <container-name>=<new-image>
-
Delete a Deployment
kubectl delete deployment <deployment-name>
Services
-
List All Services
kubectl get services
-
Expose a Deployment as a Service
kubectl expose deployment <deployment-name> --type=<service-type> --port=<port>
-
Delete a Service
kubectl delete service <service-name>
ConfigMaps and Secrets
-
Create a ConfigMap
kubectl create configmap <configmap-name> --from-literal=<key>=<value>
-
List ConfigMaps
kubectl get configmaps
-
Create a Secret
kubectl create secret generic <secret-name> --from-literal=<key>=<value>
-
List Secrets
kubectl get secrets
Logs and Debugging
-
View Pod Logs
kubectl logs <pod-name>
-
Execute Command in Pod
kubectl exec -it <pod-name> -- <command>
-
Get Events in the Cluster
kubectl get events