Skip to content

b-dorsal/kubernetes-basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes Basics Tutorial

My introduction to managing kubernetes. Trying to grow my knowledge of k8s outside of my usual GKE infrastructure configuration and troubleshooting role.

Prerequisites

  • minikube
  • kubectl
  • hyperkit
  • docker CLI

Usage

Start Minikube Cluster

Start Minikube using kyperkid VM driver

minikube start --driver=hyperkit

Create the standard namespace To-do: I'm creating everything under the same namespace. It's a tiny app so who cares.. just for demonstration purposes.

kubectl apply -f namespace.yaml

Setup Mongo

Create secrets for MongoDB username and password

echo -n 'username' | base64
echo -n 'password' | base64

Apply secrets

kubectl apply -f mongo-secret.yaml

Apply Mongo DB Deployment and Service

kubectl apply -f mongo.yaml

Apply Mongo Express Config Map

kubectl apply -f mongo-configmap.yaml

Apply Mongo Express Deployment and Service

kubectl apply -f mongo-express.yaml

Assign External IP to Mongo Express LB Service

minikube service mongo-express-service

Setup Flask App

I'm using Docker Hub...

Build the docker file

docker build -t <USERNAME>/flask-kubernetes .

Login to Docker Hub

docker login

Push the image to Docker Hub

docker push <USERNAME>/flask-kubernetes

Run the image locally to test

docker run -p 5000:5000 <USERNAME>/flask-kubernetes:latest

Apply Flask App Deployment and Service

kubectl apply -f flask-app.yaml

Apply Flask App Ingress

kubectl apply -f flask-ingress.yaml

The domain name flaskapp.com doesnt belong to me. To make this work in the local environment, add flaskapp.com to your /etc/hosts file

Get the Address from the ingress service

kubectl describe ingress -n flask-app-ns

Edit your hosts file

vim /etc/hosts

Add the hosts entry

<INGRESS ADDRESS>    flaskapp.com

Basic Commands for Checking on the Cluster

Check on your cluster

kubectl get all
kubectl get deployment
kubectl get service
kubectl get pod -o wide # helps get the IPs to compare to service endpoints
kubectl describe service <SERVICE_NAME>

Docker Hub Image Links

Migrating to Helm Chart

My next step is converting this configuration to a Helm chart. I'm interested in seeing the value of the CLI tool, Helmify, to make conversion easier.

I ran Helmify against the entire k8s directory and it seems to have succeeded.

awk 'FNR==1 && NR!=1  {print "---"}{print}' ./k8s/*.yaml | helmify flask-mongo-example-helm

To-do: run the helm chart and confirm functionality.

Deploying to Google Kubernetes Engine

The "terraform" directory contains HCL for building out a GCP project and a basic GKE-standard cluster.

Steps for Terraform

Initialize Terraform

terraform init

Run Terraform Plan

terraform plan -var-file=dev.tfvars

Run Terraform Plan

terraform apply -var-file=dev.tfvars

Deploy to the GKE cluster

Get the cluster credentials

gcloud container clusters get-credentials flask-app-cluster --region=us-central1-b

Deploy our config - still havent made this into a Helm chart

kubectl apply -f namespace.yaml
kubectl apply -f mongo-secret.yaml
kubectl apply -f mongo-configmap.yaml
kubectl apply -f mongo.yaml
kubectl apply -f flask-app.yaml
kubectl apply -f flask-ingress.yaml

Wait for an IP on ingress, and visit in a browser

kubectl get flask-ingress -n flask-app-ns

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published