Skip to content

Instantly share code, notes, and snippets.

@quangthe
Last active August 21, 2023 07:23
Show Gist options
  • Save quangthe/d8ab3146ced255b1a2cb76112121053c to your computer and use it in GitHub Desktop.
Save quangthe/d8ab3146ced255b1a2cb76112121053c to your computer and use it in GitHub Desktop.
Docker with Minikube (Replace Docker Desktop)

Installation

brew install minikube

# install docker cli only
brew install docker

brew install docker-compose

Setup

Use hyperkit driver (MacOS):

brew install hyperkit
minikube config set driver hyperkit
minikube config set container-runtime containerd
minikube config set memory 8192
minikube config set cpus 2
minikube start
minikube start \
--driver=hyperkit \
--container-runtime=docker \
--cpus='2' --memory='4g' \
--disk-size=30Gi \
--network-plugin=cni --cni calico \
--kubernetes-version=v1.24.3 

Use kvm (Linux Mint/Ubuntu)

Install kvm on Linux Mint, kvm on Ubuntu

minikube start \
--driver=kvm \
--container-runtime=docker \
--cpus='4' --memory='8g' \
--disk-size=30Gi \
--network-plugin=cni --cni calico \
--kubernetes-version=v1.24.3 

Point your shell to minikube's docker-daemon

eval $(minikube -p minikube docker-env)

Setup local-path-provisioner:

kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.22/deploy/local-path-storage.yaml

Verify setup by spinning up a docker-compose stack

git clone https://github.com/docker/awesome-compose.git
cd awesome-compose/nginx-flask-mongo
docker-compose up
$ minikube ip
192.168.99.101
  
$ curl 192.168.99.101:80
Hello from the MongoDB client!

Build and test docker image on cluster

Example repo: https://github.com/quangthe/magnolia-bootstrap

eval $(minikube docker-env)

# set ARGs
# 
docker build  \
--build-arg GIT_COMMIT=$(git rev-parse HEAD) \
--build-arg APP_VERSION=v1 \
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
-t magnolia-bootstrap .

# use --image-pull-policy=Never to force k8s lookup local imge
kubectl run test --image=magnolia-bootstrap --image-pull-policy=Never -it --rm --restart=Never -- version
{"Version":"dev","Commit":"e694081dec6fe203ec06c447030b1ec94d6e68a0","Date":"2022-07-05T03:07:26Z"}
pod "test" deleted

Addons

Metric server

minikube addons enable metrics-server

Registry

minikube addons enable registry

curl $(minikube ip):5000/v2/_catalog
{"repositories":[]}

Ingress-Nginx

minikube addons enable ingress

MetalLB

minikube addons list

minikube addons enable metallb

minikube addons configure metallb
-- Enter Load Balancer Start IP: 192.168.59.20
-- Enter Load Balancer End IP: 192.168.59.30
    ▪ Using image metallb/speaker:v0.9.6
    ▪ Using image metallb/controller:v0.9.6
✅  metallb was successfully configured
@quangthe
Copy link
Author

quangthe commented Aug 3, 2022

Clean up intermediate/temp Docker image builds in minikube

eval $(minikube docker-env)
docker image ls | grep "^<none>" | awk '{print $3}' | xargs -I {} docker image rm {}

@quangthe
Copy link
Author

quangthe commented Aug 22, 2022

minikube start \
--kubernetes-version=v1.24.3  \
--driver=kvm \
--container-runtime=docker \
--memory=6g \
--bootstrapper=kubeadm \
--extra-config=kubelet.authentication-token-webhook=true \
--extra-config=kubelet.authorization-mode=Webhook \
--extra-config=scheduler.bind-address=0.0.0.0 \
--extra-config=controller-manager.bind-address=0.0.0.0

@quangthe
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment