#Kubernetes Basics
Learn the fundamentals of Kubernetes (K8s).
#Core Concepts
| Concept | Description |
|---|---|
| Pod | Smallest deployable unit |
| Deployment | Manages ReplicaSets |
| Service | Network endpoint |
| Namespace | Virtual cluster |
| ConfigMap | Configuration data |
| Secret | Sensitive data |
#kubectl Basics
bash
1# Configure cluster access
2kubectl config get-contexts
3kubectl config use-context mycluster
4
5# Get resources
6kubectl get pods
7kubectl get deployments
8kubectl get services
9kubectl get all
10
11# Describe resource
12kubectl describe pod mypod
13
14# Logs
15kubectl logs mypod
16kubectl logs -f mypod
17
18# Execute command
19kubectl exec -it mypod -- bash
20
21# Apply configuration
22kubectl apply -f deployment.yaml
23
24# Delete resource
25kubectl delete -f deployment.yaml
26kubectl delete pod mypod#Basic Deployment
yaml
1# deployment.yaml
2apiVersion: apps/v1
3kind: Deployment
4metadata:
5 name: myapp
6spec:
7 replicas: 3
8 selector:
9 matchLabels:
10 app: myapp
11 template:
12 metadata:
13 labels:
14 app: myapp
15 spec:
16 containers:
17 - name: myapp
18 image: nginx:1.25
19 ports:
20 - containerPort: 80
21 resources:
22 limits:
23 memory: "128Mi"
24 cpu: "500m"
25---
26apiVersion: v1
27kind: Service
28metadata:
29 name: myapp-service
30spec:
31 selector:
32 app: myapp
33 ports:
34 - port: 80
35 targetPort: 80
36 type: LoadBalancer#Local Development
bash
1# minikube
2minikube start
3minikube dashboard
4
5# kind (Kubernetes in Docker)
6kind create cluster
7
8# k3d (k3s in Docker)
9k3d cluster create mycluster[!TIP] Pro Tip: Use
kubectl explain deployment.specto learn about fields!