Kubernetes hands-on tutorial slides by zm

ZiyanMaraikar1 17 views 14 slides Jul 23, 2024
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

Kubernetes hands-on tutorial slides by zm


Slide Content

Kubernetes hands-on
Managing and Exposing Applications in Kubernetes

Agenda
Introduction to Deployments
Deployment Features and Benefits
Creating and Managing Deployments
Introduction to Services
Service Types and Use Cases
Creating and Managing Services

What is a Kubernetes Deployment?
Definition: A Deployment in Kubernetes provides declarative updates to
applications. It manages the creation, updating, and deletion of Pods.
Purpose: Ensures that a specified number of pod replicas are running at any given
time.

Features and Benefits of Deployments
Declarative Updates: Define the desired state in a YAML file.
Scalability: Easily scale the number of pod replicas up or down.
Self-Healing: Automatically replace failed or unhealthy pods.
Rolling Updates: Update pods with zero downtime.
Rollback: Revert to a previous version if needed.

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80

Managing Deployments
Create a Deployment:
kubectl apply -f deployment.yaml
View Deployments:
kubectl get deployments
Scale a Deployment:
kubectl scale deployment nginx-deployment --replicas=5

Managing Deployments
Update a Deployment:
kubectl set image deployment/nginx-deployment nginx=nginx:1.19.3
Check rollout status:
kubectl rollout status deployment/nginx-deployment
Rollback a Deployment:
kubectl rollout undo deployment/nginx-deployment

What is a Kubernetes Service?
Definition: A Service in Kubernetes is an abstraction that defines a logical set of
Pods and a policy to access them.
Purpose: Provides stable endpoints for pods, enabling communication within and
outside the cluster.

Service Types and Use Cases
ClusterIP (Default): Exposes the Service on an internal IP in the cluster. Used for
internal communication.
NodePort: Exposes the Service on each Node's IP at a static port. Used for
external access.
LoadBalancer: Exposes the Service externally using a cloud provider's load
balancer.
ExternalName: Maps the Service to the contents of the externalName field (e.g., a
DNS name).

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

Creating a Service (YAML Example)
Key Fields:
●selector: Identifies the pods targeted by the service.
●ports: Defines the port mapping.
●type: Specifies the service type (e.g., LoadBalancer).

Managing Services
Create a service:
kubectl apply -f service.yaml
View services:
kubectl get services
Describe a service:
kubectl describe service nginx-service
Delete a service:
kubectl delete service nginx-service

Step 1: Create the Deployment
kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment created

Step 2: Verify the Deployment
kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 3/3 3 3 1m

kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-6799fc88d8-bwqrz 1/1 Running 0 1m
nginx-deployment-6799fc88d8-ncgxz 1/1 Running 0 1m
nginx-deployment-6799fc88d8-ws6n4 1/1 Running 0 1m

Step 3: Expose the Deployment
kubectl expose deployment nginx-deployment --type=LoadBalancer --port=80
service/nginx-deployment exposed
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP
10m
nginx-deployment LoadBalancer 10.96.219.242 203.0.113.25 80:30847/TCP
1m