Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


Kubernetes: Guía para detener, ejecutar y desplegar. - Prof. Jiménez Arenas, Diapositivas de Informática

Este documento contiene instrucciones detalladas para detener un clúster Kubernetes localmente usando Minikube, ejecutar comandos kubectl y desplegar aplicaciones en Kubernetes. El documento incluye pasos para instalar el software requerido, configurar el entorno de desarrollo y ejecutar diferentes labores para practicar los comandos kubectl y desplegar aplicaciones. Estas labores abarcan el uso de pods, servicios, configmaps y secretos.

Tipo: Diapositivas

2022/2023

Subido el 09/12/2022

juan-llenas-rafales
juan-llenas-rafales 🇪🇸

3 documentos

1 / 21

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
Kubernetes Lab Guide
0
KUBERNETES - LAB GUIDE
PREMKUMAR NATARAJAN
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Vista previa parcial del texto

¡Descarga Kubernetes: Guía para detener, ejecutar y desplegar. - Prof. Jiménez Arenas y más Diapositivas en PDF de Informática solo en Docsity!

KUBERNETES - LAB GUIDE

PREMKUMAR NATARAJAN

Table of Contents

1 Purpose

This document will lay out the details to setup the Kubernetes in window 7 64 bit OS environment and practice the Lab exercises.

2 Prerequisites

Kubernetes exercise are performed on Windows 7 Professional OS using minikube tool

2.1 Software Download

S.No Software Download Location File Name Version

1 Minikube https://github.com/kubernetes/minikube/releases/t ag/v0.25.

minikube- windows- amd

Windows 64 Bit

2 Kubectl https://storage.googleapis.com/kubernetes- release/release/v1.11.0/bin/windows/amd64/kubec tl.exe

Kubectl.exe Kubectl CLI

3 LAB-01: Install Minikube in Windows

This LAB exercise shows you how to install Minikube.

Minikube is an open source tool that was developed to enable developers and system administrators to run a single cluster of Kubernetes on their local machine. Minikube starts a single node kubernetes cluster locally with small resource utilization.

3.1 Time to Complete

Approximately 0.30 Hr.

3.2 Environment

  1. Windows 7 Professional

3.3 What You Need

3.3.1 Pre-setup

  1. BIOS VT-x enabled for Virtual Machines to come up
  2. Turn off the hyperv in windows Using VirtualBox and not Hyper-V VirtualBox and Hyperv (which is available on Windows 10) do not make a happy pair and you are bound to run into situations where the tools get confused. I preferred to use VirtualBox and avoid all esoteric command-line switches that we need to provide to enable creation of the underlying Docker hosts, etc.

To disable Hyper-V, go to Turn Windows features on or off and you will see a dialog with list of Windows features as shown below. Navigate to the Hyper-V section and disable it completely. a. If hyperv is running i. Search for "turn windows feature on or off" ii. uncheck "Hyper-V"

  1. Requires VirtualBox - If it is already installed then there is no need for a new setup. Else download and install from www.virtualbox.org
  1. From the above command prompt execute " kubectl version "
  2. Use the kubectl CLI to get the cluster information: “ kubectl cluster-info

3.4.6 Cluster IP Address

  1. Get the IP address of the cluster via the ip command “ minikube ip

3.4.7 Kubernetes Dashboard

  1. Launch the Kubernetes Dashboard at any point via the dashboard command as shown below: “ minikube dashboard”

This will automatically launch the Dashboard in your local browser.

However if you just want to nab the Dashboard URL, you can use the following flag: “ minikube.exe dashboard --url=true http://192.168.99.100:30000

Click on the Node link and you will see that information:

The above node information can also be obtained by using the kubectl CLI to get the list of nodes. “ kubectl get nodes

3.4.8 Stop the Kubernetes Cluster

  1. Run the below command to stop the Kubernetes cluster using command “ minikube stop
  2. Check the status of cluster using minikube command “ minikube status

<<<<>>>>

5 LAB- 03 : Deploy Application Install Minikube in Windows

This LAB exercise shows you how to deploy a sample application in kubernetes.

5.1 Time to Complete

Approximately 0.30 Hr.

5.2 What You Need

  1. Lab 01 to completed successfully.
  2. Kubernetes Cluster should be running. If not start the cluster using the command “minikube start”

5.3 Deploy the Application

With Kubernetes cluster ready, start deploying application containers. The application container deploying will

be an instance of Ghost.

Ghost is a popular JavaScript-based blogging platform, and with its official Docker image.

  1. Open the command prompt as administrator.
  2. Use the below command to start Ghost container. kubectl run ghost --image=ghost --port=
  3. Verify that the container is running using the below command. kubectl get pods
  4. To make Ghost application accessible outside the cluster, the deployment just created needs to be exposed as a Kubernetes Service. kubectl expose deployment ghost --type="NodePort"

NodePort service type will set all nodes to listen on the specified port.  ClusterIP is to only expose service to other Pods within this cluster  LoadBalancer service type is designed to provision an external IP to act as a Load Balancer for the service.

  1. To get the port assigned, use the kubectl command, with the describe service option. kubectl describe service ghost
  2. Scale the deployment using the below command : kubectl scale deployment ghost --replicas=
  1. Get the status of the deployment using the below command : kubectl get deployment
  2. Open the dashboard using the command minikube dashboard
  3. From Dashboard, go to the Services section, check services entry.
  4. Open the service using the command : minikube service ghost

<<<<>>>>

7 LAB- 05 : Deploy multiple POD and communication between POD in Kubernetes

This LAB exercise demonstrate the concept of packaging containers into a pod and communication between pods.

7.1 Time to Complete

Approximately 0.30 Hr.

7.2 What You Need

  1. Lab 01 to completed successfully.
  2. Kubernetes Cluster should be running. If not start the cluster using the command “minikube start”

7.3 Build a Docker image and push it to docker hub

  1. Login to the Docker machine.
  2. Copy all the file from the Folder PODLab from git Location : https://github.com/premkumarmlp/KubernetesExercises.git
  3. Edit the below files in the Docker folder as per your docker hub username.  build.shdocker-compose.yml Ex: Replace the username/repository from premkumarmlp/web to your username/ in docker hub.
  4. From the docker directory, build the image using below commnd. dockeruser@dockeruser-VirtualBox:~/K8sPODLab/Docker$ docker build - t /web.
  5. Once the build is successful, push the image to your docker hub. dockeruser@dockeruser-VirtualBox:~/K8sPODLab/Docker$ docker push /web
  6. To check the build image is working properly, use the docker compose file to create the container using below command. dockeruser@dockeruser-VirtualBox:~/K8sPODLab/Docker$ docker-compose up - d
  7. Check the container using below command. dockeruser@dockeruser-VirtualBox:~/K8sPODLab/Docker$ docker ps - a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5f8e8f025b66 premkumarmlp/web "python app.py" 27 seconds ago Up 24 seconds 0.0.0.0:3000->5000/tcp docker_web_
  8. Test the application using the url http://localhost:3000/ and the output will be as : Hello Container World! I have been seen 1 times. Now you build image is ready to deploy in Kubernetes.

7.4 Deploy the Application in Kubernetes

  1. Login to the kubernetes machine
  2. Copy all the file from the Folder PODLab from git Location and store it locally. (example : D:\PODLab): https://github.com/premkumarmlp/KubernetesExercises.git
  3. Edit the below files in the Kubernetes folder as per your docker hub username. web-pod.yml web-rc.yml Ex: Replace the username/repository from premkumarmlp/web to your username/ in docker hub.
  4. Open the command prompt as administrator and create POD service as below

C:\Windows\system32>kubectl create -f D:\PODLab\db-pod.yml pod/redis created C:\Windows\system32>kubectl create -f D:\PODLab\db-svc.yml service/redis created C:\Windows\system32>kubectl create -f D:\PODLab\web-pod.yml pod/web created C:\Windows\system32>kubectl create -f D:\PODLab\web-svc.yml service/web created C:\Windows\system32>kubectl create -f D:\PODLab\web-rc.yml replicationcontroller/web created

  1. Get the list of PODs and verify all are running. C:\Windows\system32> kubectl get pods NAME READY STATUS RESTARTS AGE redis 1/1 Running 0 32s web 1/1 Running 0 18s web-v5x9l 1/1 Running 0 4s
  2. Get the list of exposed services.

C:\Windows\system32> kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 443/TCP 16h redis ClusterIP 10.102.49.56 6379/TCP 49s web NodePort 10.101.202.109 80:31017/TCP 33s

  1. Get service url for web application using below command. C:\Windows\system32> minikube service web --url http://192.168.99.102:
  2. Access the url from the browser and verify the result.

Hello Container World! I have been seen 4 times.

<<<<>>>>

  1. Get the minikube service url for this tomcat service using the command : C:\Windows\system32>minikube service tomcat-deployment --url http://192.168.99.102:
  2. Open the browser and access the service URL. Check the tomcat home page is loading and version.

8.4 Upgrade the Application with different tomcat version

  1. Update deployment of object tomcat to version 8.0 using the command : C:\Windows\system32>kubectl set image deployment/tomcat-deployment tomcat= tomcat:8. deployment.extensions/tomcat-deployment image updated
  2. Check the PODs are running using the below command C:\Windows\system32>kubectl get pods It will take some time, since 8.0 version of tomcat need to be pulled. Once the tomcat POD is running, then expose the service.
  3. Expose the service using the command. C:\Windows\system32>kubectl expose deployment tomcat-deployment --type=NodePort
  4. Get the minikube service url for this tomcat service using the command : C:\Windows\system32>minikube service tomcat-deployment – url http://192.168.99.102: Open the browser and access the service URL. Check the tomcat home page is loading.
  5. Get the minikube service url for this tomcat service using the command : C:\Windows\system32>minikube service tomcat-deployment --url http://192.168.99.102:
  6. Open the browser and access the service URL. Check the tomcat home page is loading and version.

8.5 Rollout the previous deployed version

  1. Rollout the changes applied to the deployment object using below command.

kubectl rollout undo deployment/tomcat-deployment deployment.extensions/tomcat-deployment It will take some time, since 8.0 version of tomcat need to be pulled. Once the tomcat POD is running, then expose the service.

  1. Get the minikube service url for this tomcat service using the command : C:\Windows\system32> minikube service tomcat-deployment --url http://192.168.99.102:
  2. Open the browser and access the service URL. Check the tomcat home page is loading and version.

<<<<>>>>

<<<<>>>>

10 LAB- 08 : ConfigMaps in Kubernetes

This LAB exercise shows you how to apply ConfigMaps in kubernetes.

10.1 Time to Complete

Approximately 0.30 Hr.

10.2 What You Need

  1. Lab 01 to completed successfully.
  2. Kubernetes Cluster should be running. If not start the cluster using the command “minikube start”

10.3 Deploy the Application

Download the files from folder ConfigMap of Git location: https://github.com/premkumarmlp/KubernetesExercises.git

  1. Create a generic secret from YAML file kubectl create -f my-secret.yml
  2. Create the POD kubectl create -f secret-env-pod.yml
  3. Access the Secret in the POD kubectl exec -it secret-env-pod /bin/sh

env

  1. Clean up kubectl delete -f my-secret.yml -f secret-env-pod.yml

<<<<>>>>