โ๏ธ Kubernetes Introduction Visit Kubernetes Home Page โ Explore More Topics
๐ What is Kubernetes?
Kubernetes (or K8s) is an open-source platform for automating deployment, scaling, and management of containerized applications.
Example: Think of Kubernetes as a traffic controller for containersโdirecting each container to the right server.
# Check Kubernetes version
kubectl version --short
# Get cluster information
kubectl cluster-info
โ๏ธ Kubernetes vs. Docker vs. Container Runtime
Docker builds and runs containers, while Kubernetes orchestrates them across a cluster. A container runtime (like containerd or CRI-O) is the engine that actually runs containers.
Example: Docker creates a container image, Kubernetes schedules containers, and containerd runs them on your host.
# Build a Docker image
docker build -t myapp:latest .
# Deploy the image using Kubernetes
kubectl apply -f deployment.yaml
# Verify the rollout
kubectl rollout status deployment/my-deployment
๐ What is a Container Runtime?
A container runtime is the underlying software that executes containers on a host. Kubernetes supports several, including containerd and CRI-O.
Example: Use containerd to run your containers efficiently on each node.
# Check containerd version
containerd --version
๐ฆ What is a Pod?
A Pod is the smallest deployable unit in Kubernetes, consisting of one or more containers that share network and storage resources.
Example: A Pod might run an Nginx container along with a sidecar container for logging.
# pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.19
ports:
- containerPort: 80
# Troubleshoot a pod
kubectl describe pod nginx-pod
kubectl logs nginx-pod
๐ข What is a Namespace?
Namespaces allow you to partition a Kubernetes cluster into virtual sub-clusters, keeping resources isolated.
Example: Use separate namespaces like dev
, test
, and prod
for different environments.
# List namespaces
kubectl get namespaces
# Create a new namespace
kubectl create namespace my-namespace
๐ What is a Secret?
Secrets store sensitive information such as passwords, API keys, and certificates securely.
Example: Use a Secret to store a database password without exposing it in your code.
# Create a secret
kubectl create secret generic db-secret --from-literal=password=mysecret
# View secret details
kubectl describe secret db-secret
โ๏ธ What is a ConfigMap?
ConfigMaps store non-sensitive configuration data that can be injected into Pods at runtime.
Example: A ConfigMap might hold an applicationโs logging level or other settings.
# Create a ConfigMap from a file
kubectl create configmap app-config --from-file=config.properties
# configmap.yaml example
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
LOG_LEVEL: debug
config.properties: |
cache.size=100MB
timeout=30s
๐ What is a Service?
A Service provides a stable network endpoint to access a set of Pods, even if the underlying Pods are updated.
Example: Expose a web server Pod on port 80 so users can reliably access your application.
# service.yaml example
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
selector:
app: web
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
๐ What is an Ingress?
Ingress manages external access to the Services in your cluster, typically handling load balancing, routing, and SSL termination.
Example: Route traffic for myapp.example.com
to a specific service.
# ingress.yaml example
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
๐ What is a Deployment?
A Deployment automates the creation, scaling, and updating of Pods via ReplicaSets.
Example: Deploy an application with three replicas and update them gradually during a rollout.
# deployment.yaml example
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deploy
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.19
ports:
- containerPort: 80
๐ What is a DaemonSet?
A DaemonSet ensures that a copy of a Pod runs on all (or selected) nodes in the cluster.
Example: Deploy a logging agent on every node.
# List daemonsets
kubectl get daemonset
# Describe a specific daemonset
kubectl describe daemonset
๐ What is a StatefulSet?
StatefulSets manage stateful applications, ensuring each Pod has a stable identity and persistent storage.
Example: Use a StatefulSet for databases that require stable network identities.
# List statefulsets
kubectl get statefulset
# Describe a specific statefulset
kubectl describe statefulset
๐ What is Horizontal Pod Autoscaler (HPA)?
HPA automatically scales the number of Pod replicas based on real-time metrics like CPU or memory usage.
Example: Scale your web application to handle increased traffic.
# List HPAs
kubectl get hpa
# Describe HPA for a deployment
kubectl describe hpa
โ๏ธ What is Vertical Pod Autoscaler (VPA)?
VPA adjusts the resource requests and limits of Pods dynamically based on actual usage.
Example: Increase a container's memory allocation when it consistently exceeds its current limit.
# List VPAs
kubectl get vpa
# Describe a VPA
kubectl describe vpa
๐ ๏ธ What is a Job & CronJob?
A Job ensures that a task runs to completion once, while a CronJob schedules Jobs to run periodically.
Example: Run a one-time migration with a Job, or schedule regular backups with a CronJob.
# List Jobs
kubectl get jobs
# List CronJobs
kubectl get cronjob
๐ What is Role-Based Access Control (RBAC)?
RBAC manages permissions in Kubernetes by defining roles and binding them to users, groups, or service accounts.
Example: Ensure that only authorized personnel can modify critical cluster resources.
# List roles and rolebindings
kubectl get roles
kubectl get rolebindings
๐ฆ What is Helm?
Helm is a package manager for Kubernetes that simplifies deployment using reusable charts.
Example: Deploy a complete application stack, such as WordPress with MySQL, with a single command.
# Install a Helm chart
helm install my-release my-chart
# List Helm releases
helm list
๐ What is an Operator?
An Operator extends Kubernetes by automating the management of complex stateful applications using custom controllers.
Example: A database Operator might automate tasks like backups, scaling, and updates.
๐ข Stay tuned!
We'll continue adding more insights on Kubernetes, covering advanced topics like Multi-Cluster management, custom resource definitions (CRDs), and more.