Kubernetes Hands-On Lab - Deploying a Simple Service to Kubernetes

Kubernetes Hands-On Lab - Deploying a Simple Service to Kubernetes

Kubernetes Learning Path for Cloud and DevOps Engineers

📝Introduction

In this lab, we will have an opportunity to get hands-on with a Kubernetes cluster and build a simple deployment, coupled with a service providing access to it. You will create a deployment and a service which can be accessed by other pods in the cluster (previously created).

These are the objectives of this lab:

  • Create a deployment for the store-products service with four replicas.

  • Create a store-products service and verify that you can access it from the busybox testing pod.

    📌Note: In this lab, I am using a busybox pod for testing purposes. A busybox provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, curl commands, etc. It is a good tool for debugging and troubleshooting issues in a Linux environment and Kubernetes runs on Linux.

📝Log in to the AWS Management Console

Using your credentials, make sure you're using the right Region. In my case, I am using AWS as my cloud provider and chose us-east-1. However, for this hands-on lab, you can select any cloud provider to create your Linux server VMs (I am using an Ubuntu 18.04 LTS distro) and Kubernetes 1.27 (1 Master Node and 2 Worker Nodes).

📌Note: You must create the AWS Access Key and AWS Secret Access Key and configure the AWS CLI in the terminal to use it.

You can use link1 and link2 for it.

📝Create a deployment for the store-products service with four replicas

  1. Log in to your Kube master node.

  2. Create the deployment with four replicas:

     cat << EOF | kubectl apply -f -
     apiVersion: apps/v1
     kind: Deployment
     metadata:
       name: store-products
       labels:
         app: store-products
     spec:
       replicas: 4
       selector:
         matchLabels:
           app: store-products
       template:
         metadata:
           labels:
             app: store-products
         spec:
           containers:
           - name: store-products
             image: linuxacademycontent/store-products:1.0.0
             ports:
             - containerPort: 80
     EOF
    

📝Create a store-products service and verify that you can access it from the busybox testing pod

  1. Create a service for the store-products pods:

     cat << EOF | kubectl apply -f -
     kind: Service
     apiVersion: v1
     metadata:
       name: store-products
     spec:
       selector:
         app: store-products
       ports:
       - protocol: TCP
         port: 80
         targetPort: 80
     EOF
    
  2. Make sure the service is up in the cluster:

     kubectl get svc store-products
    

    The output will look something like this:

     NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
     store-products   ClusterIP   10.110.101.158   <none>        80/TCP    6s
    
  3. Use kubectl exec to query the store-products service from the busybox testing pod.

    📌Note: Busybox pod image used in this lab to run curl command: radial/busyboxplus:curl

    However, you can also use this other Busybox pod image to run curl command: curlimages/curl:latest

     kubectl exec busybox -- curl -s store-products
    

📌Note - At the end of each hands-on Lab, always clean up all previous resources created to avoid being charged if you used a Cloud Provider to provision them.

Congratulations — you have completed this hands-on lab covering the basics of creating a simple deployment and a service which can be accessed by other pods in the cluster.

Thank you for reading. I hope you understood and learned something helpful from my blog.

Please follow me on CloudDevOpsToLearn and LinkedIn, franciscojblsouza