Skip to content

Instantly share code, notes, and snippets.

@sau-lanvy
Last active April 10, 2020 10:05
Show Gist options
  • Save sau-lanvy/8fec8600b4b1cdf8f8f22c0505979940 to your computer and use it in GitHub Desktop.
Save sau-lanvy/8fec8600b4b1cdf8f8f22c0505979940 to your computer and use it in GitHub Desktop.
Prerequisites
- Docker
- kubectl
- Minikube
- Helm
Noted: This guide is just for Macbook Pro. I would like to it supports the both Linux and Windows later.
1. Set up a registry server
You can follow the guide from the docker for creating a [local registry](https://docs.docker.com/registry/deploying/)
$ docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
registry:2
2. Setup in local machine
- Edit /etc/hosts to add this line:
127.0.0.1 registry.local
- Now tag your image properly:
docker tag my-image registry.local:5000/my-image:0.0.1
- Push your image to local registry:
docker push registry.local:5000/my-image:0.0.1
- Verify that image is pushed:
curl -X GET http://registry.local:5000/v2/my-image/tags/list
- Get your host machine's ip
ipconfig getifaddr en0 -> 192.168.x.x
3. Start the Minikube cluster
- (optional) Set the default VM driver
minikube config set vm-driver [driver_name]
(Note: See DRIVERS for details on supported drivers and how to install plugins.)
- Start the cluster Use 1.13.x or newer version of Kubernetes with --kubernetes-version
minikube start --cpus=4 --memory=4096 --kubernetes-version=1.16.2
or run the following command:
minikube start
- Enable dashboard
minikube addons enable dashboard
4. Setup in minikube
You can follow the guide from minikue website to enable insecure registry support within minikube at: https://minikube.sigs.k8s.io/docs/tasks/registry/insecure/
else follow below steps each time you start new minikube cluster:
- ssh into minikube with:
minikube ssh
- edit /etc/hosts to add this line
192.168.x.x registry.local
- Try to pull the image:
docker pull registry.local:5000/my-image:0.0.1
You might get an http access error. -> Error response from daemon: Get https://registry.local:5000/v2/: http: server gave HTTP response to HTTPS client
- For the TLS issue you need to Stop the docker service inside minikube
systemctl stop docker (maybe you need: sudo)
- Get the path of the docker serice file
systemctl status docker
-> /usr/lib/systemd/system/docker.service
- Edit the docker serice file by append this this:
--insecure-registry registry.local:5000
to this line:
ExecStart= .... --insecure-registry 10.96.0.0/12
- Then reload daemon and start the docker service
systemctl daemon-reload
systemctl start docker
- After that try to pull again
docker pull registry.local:5000/my-image:0.0.1
-> The command shoul work with the status: Downloaded newer image for registry.local:5000/my-image:0.0.1
5. Set up Ingress on Minikube with the NGINX Ingress Controller
- To enable the NGINX Ingress controller, run the following command:
minikube addons enable ingress
- Verify that the NGINX Ingress controller is running
kubectl get pods -n kube-system
6. Test with a hello, world app
- Create a Deployment using the following command:
kubectl run web --image=gcr.io/google-samples/hello-app:1.0 --port=8080
- Expose the Deployment:
kubectl expose deployment web --target-port=8080 --type=NodePort
- Visit the service via NodePort:
minikube service web --url
-> You can now access the sample app via the Minikube IP address and NodePort.
7. Expose app publicly
We can use a great tool called ngrok to dynamically generate a new hostname on a public domain and have it create a tunnel into our machine and forward requests onto our Minikube cluster.
- Go to https://ngrok.com
- Register a free account
- Following the Setup & Installation
- Start a HTTP tunnel on port 80
ngrok http $(minikube ip):80
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://83e92f46.ngrok.io -> http://192.168.64.2:80
Forwarding https://83e92f46.ngrok.io -> http://192.168.64.2:80
At this point you should now be able to open a browser and see 404 Not Found from (http://[your-value].ngrok.io)
8. Create an ingress resource to expose the app on the standard http port
- Create example-ingress.yaml from the following file:
apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: 83e92f46.ngrok.io
http:
paths:
- path: /
backend:
serviceName: web
servicePort: 8080
- Create the Ingress resource by running the following command:
kubectl apply -f example-ingress.yaml
Now you should now be able to open a browser to the http forwarding address as specified in the ngrok output above and access the application.
-- Well Done ---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment