Hasan's Post

Tutorial repository

View on GitHub
21 August 2022

Introduction to kubernetes

by Hasan

objectives

Use kubectl CLI

Creating a pod

Creating pod with imperative command

Creating pod with imperative object configuration

Creating a pod using declarative command(deployment, replica)

Load balancing the application

  1. kubectl expose deployment/hello-world - will expose the app. This command creates what is called a ClusterIP Service. This creates an IP address that accessible within the cluster.
  2. List Services in order to see that this service was created. kubectl get services
  3. Open a new terminal window using Terminal > Split Terminal.
  4. Since the cluster IP is not accessible outside of the cluster, we need to create a proxy. Note that this is not how you would make an application externally accessible in a production scenario. Run this command (kubectl proxy)in the new terminal window since your environment variables need to be accessible in the original window for subsequent commands.This command doesn’t terminate until you terminate it. Keep it running so that you can continue to access your app.:w
  5. In the original terminal window, ping the application to get a response.
    curl -L localhost:8001/api/v1/namespaces/sn-labs-$USERNAME/services/hello-world/proxy
    
  6. Run the command which runs a for loop ten times creating 10 different pods and note names for each new pod.
    for i in `seq 10`; do curl -L localhost:8001/api/v1/namespaces/sn-labs-$USERNAME/services/hello-world/proxy; done
    
  7. You should see more than one Pod name, and quite possibly all three Pod names, in the output. This is because Kubernetes load balances the requests across the three replicas, so each request could hit a different instance of our application.
  8. Delete the Deployment and Service. This can be done in a single command by using slashes.kubectl delete deployment/hello-world service/hello-world
  9. Return to the terminal window running the proxy command and kill it using Ctrl+C.

Cheat sheet

Command Description

tags: