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

Kubernetes hands-on tutorial slides by zm

  • 1.
    Kubernetes hands-on Managing andExposing Applications in Kubernetes
  • 2.
    Agenda Introduction to Deployments DeploymentFeatures and Benefits Creating and Managing Deployments Introduction to Services Service Types and Use Cases Creating and Managing Services
  • 3.
    What is aKubernetes 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.
  • 4.
    Features and Benefitsof 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.
  • 5.
    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
  • 6.
    Managing Deployments Create aDeployment: kubectl apply -f deployment.yaml View Deployments: kubectl get deployments Scale a Deployment: kubectl scale deployment nginx-deployment --replicas=5
  • 7.
    Managing Deployments Update aDeployment: 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
  • 8.
    What is aKubernetes 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.
  • 9.
    Service Types andUse 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).
  • 10.
    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).
  • 11.
    Managing Services Create aservice: 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
  • 12.
    Step 1: Createthe Deployment kubectl apply -f nginx-deployment.yaml deployment.apps/nginx-deployment created
  • 13.
    Step 2: Verifythe 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
  • 14.
    Step 3: Exposethe 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