0% found this document useful (0 votes)
3 views

Key Concepts Unveiled

The document provides an overview of key concepts in Kubernetes and Docker, including Pods, Containers, Deployments, and their differences. It also outlines Kubernetes architecture components, service types, and daily management activities. Additionally, it explains the roles of Kubelet and Kube-Proxy, as well as how to manage namespaces and deployments.

Uploaded by

Kiran Animestar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Key Concepts Unveiled

The document provides an overview of key concepts in Kubernetes and Docker, including Pods, Containers, Deployments, and their differences. It also outlines Kubernetes architecture components, service types, and daily management activities. Additionally, it explains the roles of Kubelet and Kube-Proxy, as well as how to manage namespaces and deployments.

Uploaded by

Kiran Animestar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Pod vs Container vs Deployment


Pod
A Pod is the smallest deployable unit in Kubernetes and can contain one or more containers.
# pod-example.yml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
ports:
- containerPort: 80

Create Pod:
kubectl apply -f pod-example.yml

Container
A container is a lightweight, standalone executable package of software. In the above example,
nginx is a container running inside a pod.

Deployment
A Deployment manages multiple pod replicas and provides updates/rollbacks.
# deployment-example.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80

Create Deployment:
kubectl apply -f deployment-example.yml

2. Docker vs Kubernetes
Docker
Docker is used to create, manage, and run containers.
Build Docker Image:
docker build -t myapp:latest .

Run Container:
docker run -d -p 8080:80 myapp:latest

Kubernetes
Kubernetes orchestrates containers across multiple nodes.
Deploy on Kubernetes:
# k8s-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: k8s-app
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:latest
ports:
- containerPort: 8080

Apply to Cluster:
kubectl apply -f k8s-deployment.yml
3. Main Components of Kubernetes Architecture
• API Server: Accepts commands (e.g., kubectl) and manages cluster state.
• Etcd: Stores configuration data.
• Controller Manager: Ensures cluster state matches the desired state.
• Scheduler: Assigns pods to nodes.
• Kubelet: Runs on nodes to manage pod lifecycle.
• Kube-Proxy: Handles network routing.
• Container Runtime: Runs containers (e.g., Docker, containerd).
Example: To view cluster components:
kubectl get componentstatuses

4. Docker Swarm vs Kubernetes


Docker Swarm
# Initialize Swarm
docker swarm init

# Deploy Service
docker service create --name myweb --replicas 3 -p 8080:80 nginx

Kubernetes
# deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
kubectl apply -f deployment.yml

5. Docker Container vs Kubernetes Pod


Docker Container:
docker run -d --name my-container -p 8080:80 nginx

Kubernetes Pod:
# pod-example.yml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80

kubectl apply -f pod-example.yml

6. Namespace in Kubernetes
# Create Namespace
kubectl create namespace dev-environment

# Deploy in Namespace
kubectl apply -f deployment.yml -n dev-environment

# Check Namespaces
kubectl get namespaces

7. Role of Kube-Proxy
• Handles routing rules for traffic between pods and services.
• Ensures services are reachable within the cluster.
Example: Check kube-proxy
kubectl get pods -n kube-system | grep kube-proxy
8. Deployment vs ReplicaSet
Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
replicas: 2
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: nginx
image: nginx

ReplicaSet:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend-rs
spec:
replicas: 2
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: nginx
image: nginx

9. Different Services in Kubernetes


• ClusterIP:
apiVersion: v1
kind: Service
metadata:
name: clusterip-service
spec:
type: ClusterIP
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80

• NodePort:
apiVersion: v1
kind: Service
metadata:
name: nodeport-service
spec:
type: NodePort
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30007

• LoadBalancer:
apiVersion: v1
kind: Service
metadata:
name: lb-service
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80

10. NodePort vs LoadBalancer


• NodePort: Exposes the service on each node's IP at a specific port.
• LoadBalancer: Provisions an external load balancer to expose the service outside the
cluster.

11. Role of Kubelet


• Runs on each node.
• Ensures containers are running in pods.
• Communicates with the API server.
Example: Check Kubelet logs
journalctl -u kubelet -f

12. Day-to-Day Activities in Kubernetes


• Managing deployments, scaling, and updates.
• Monitoring health and resource usage.
• Troubleshooting pod and node issues.
• Managing namespaces, roles, and security policies.

13. What is an Image in Containers in Kubernetes?


• A template used to create containers.
• Stored in container registries like Docker Hub or GCR.
docker build -t myapp:latest .
docker push myapp:latest

14. Labels and Selectors in Kubernetes


metadata:
labels:
app: frontend

Selectors are used in services and ReplicaSets to target pods:


selector:
matchLabels:
app: frontend

15. How to Delete a Deployment in Kubernetes?


kubectl delete deployment <deployment-name>

You might also like