unfor19 / kubernetes-quickstart

Getting started with Kubernetes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kubernetes-quickstart

Topics

  • Basic understanding of Kubernetes
  • Creating a local development environment for hands-on experience with Kubernetes
  • Deploying an application to Kubernetes for the first time ever
  • Playing with Kubernetes Pod autoscaling

Requirements

  • Docker Desktop
  • minikube - For local development with Kubernetes (cross-platform)
  • LENS - The Kubernetes IDE
  • Helm - Kubernetes packages (charts) manager
  • ab - Apache HTTP server benchmarking tool
    • Windows - choco install apache-httpd
    • macOS - natively installed from BigSur 11+

Getting Started

  1. Clone this repo

  2. Create a Kubernetes cluster locally

    minikube start --kubernetes-version=1.24.0

    Note: For beginners, it's best to start from version 1.24.0 as version 1.25.0 includes breaking changes such as the removal of PSP which breaks a lot of Helm charts.

  3. Deploy nginx ingress controller to enable traffic from "the internet" to the cluster

    helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx && \
    helm repo update && \
    helm upgrade --namespace kube-system --install nginx ingress-nginx/ingress-nginx
  4. To access the NGINX Ingress Controller from the Host machine (macOS/Windows), we need to map its domain name to 127.0.0.1, which will listen to ports 80 and 443.

    1. Edit the hosts file
      • macOS: Edit /etc/hosts with your favotire editor
      sudo vim /etc/hosts
      • Windows: Edit C:\Windows\System32\drivers\etc\hosts with Notepad or Notepad++ as Administrator
    2. Add the following line
    127.0.0.1 quickstart.kubemaster.me
  5. Verify with LENS that the nginx-ingress-controller has an External IP 127.0.0.1 - otherwise you won't be able to receive traffic from the host machine (your PC)

  6. Deploy the "quickstart" application - docker-cats

    kubectl apply -f app.yml
  7. Start minikube tunnel to allow traffic from the host machine to the Kubernetes cluster ingresses

    # Execute in a separated terminal - keep it running
    sudo minikube tunnel
  8. Test the deployment - Navigate to http://quickstart.kubemaster.me

  9. (Optional) For further learning about HTTPS and authentication, see kubernetes-localdev

Recap

  1. nginx-ingress-controller - deployed with Helm

  2. docker-cats - deployed with kubectl

    1. Deployment - A Deployment provides declarative updates for Pods and ReplicaSets.
    2. Service - network abstraction to route traffic to the application and the ability to access the application internally in the cluster with the Service DNS record quickstart.default.svc.local
    3. Ingress - An API object that manages external access to the services in a cluster, typically HTTP. Ingress may provide load balancing, SSL termination and name-based virtual hosting.

Autoscaling

  1. Deploy Kubernetes Metrics Server - need to collect metrics such as CPU and Memory of pods to autoscale

    helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/ && \
    helm upgrade --namespace kube-system --install metrics-server metrics-server/metrics-server --values metrics-server-values.yml
  2. Apply a Horizontal Pod Autoscaler object

    kubectl apply -f hpa.yml
  3. Test autoscaling with ab

    ab -k -v1 -n 100000 -c 100 -s 60 http://quickstart.kubemaster.me/
    • -k - KeepAlive feature, performs multiple requests within one HTTP session. Default is no KeepAlive. If you skip this flag, you'll get Total of 16314 requests completed on macOS, see this Stackoverflow answer
    • -v1 - Verbosity level
    • -n - Number of requests
    • -c - Number of parallel requests
    • -s - Timeout in seconds, the default is 30 seconds
  4. View scaling up and down in LENS

Authors

Created and maintained by Meir Gabay

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Getting started with Kubernetes

License:MIT License