Skip to content

gimmeursocks/docker-k8s-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevOps Challenge: Fix & Deploy Go App with Redis

Deploy Status

Overview

  • My task is to troubleshoot, fix, and deploy a Go web application that uses Redis for caching. There are some issues in the Dockerfile or the Go code. After fixing these issues, the app is to be deployed to a Kubernetes cluster with Redis.

Part 1: Fix the Dockerfile and Go Application

  • Fixed bug in CMD ["bin/myapp"] to CMD ["app/myapp"]
  • Changed PORT to 8080 to ensure clarity
  • Set up a Redis container using docker-compose and passed its environment variables
  • Optimized image size using multistage builds through golang:1.23-alpine and a scratch image, effectively reducing image size from 1.03GB to 5.71MB (~99.45% size reduction!!!)

Proof

docker-compose

docker-compose up --build

docker-logs

docker compose logs app

docker-ps-and-curl

docker ps & curl http://localhost:8080

docker-images

docker images (notice the reduction in image size!!)

Part 2: Deploy to Kubernetes

  • Created Kubernetes YAML files and deployed Go (as stateless workload) and Redis (as stateful workload)
  • Used separate namespaces: app & db
  • Set up PVC for Redis persistent storage
  • Set up clusterIP as none to make network ID stable
  • Used configmap to manage variables
  • Utilized one pod per each workload
  • Uploaded local image to docker hub publicly gimmeursocks/docker-k8s-challenge_app
  • Used nodeport due to local deployment using minikube
  • Exposed Redis internally with stateful state with static hostname

Proof

k8s-namespaces

kubectl apply -f namespaces.yaml

k8s-stateless

kubectl apply -f go-deployment.yaml
kubectl apply -f go-service-nodeport.yaml

k8s-stateful

kubectl apply -f redis-pvc.yaml
kubectl apply -f redis-statefulset.yaml
kubectl apply -f redis-service.yaml

k8s-verify-namespaces_app k8s-verify-namespaces_db

kubectl get all -n app
kubectl get all -n db

docker-upload-image

docker tag & docker push

docker-upload-image

docker tag & docker push

k8s-curl

curl result

k8s-stateful-pvc

Redis persistent storage

k8s-redis-pod-describe-1 k8s-redis-pod-describe-2

kubctl describe pod redis-0 -n db

k8s-configmap

Managing variables

k8s-one-per-one

One pod per each workload

k8s-nodeport

Port exposure using nodeport

k8s-redis-internal

Internal communication between Redis

k8s-conclusion

Pods and Services

Bonus

  • Created Github Action workflow to automatically build and test the deployment of k8s
  • Auto builds using docker compose and then pushes to docker hub
  • It tests the deployment of k8s by installing and running minikube in the workflow
  • Then waits for successful deployment to curl into it

cicd-service-urls

Testing service URLs in the new deployment

cicd-debug-info

Showing relevant debug information

cicd-curl-test

Testing application through curl

About

Troubleshoot, fix, and build a Go web application that uses Redis for caching, then deploy using k8s.

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •