Skip to content

Instantly share code, notes, and snippets.

@nhthai2005
Last active April 16, 2022 10:13
Show Gist options
  • Save nhthai2005/4e54a5027f43d5cf0de781e30224eb19 to your computer and use it in GitHub Desktop.
Save nhthai2005/4e54a5027f43d5cf0de781e30224eb19 to your computer and use it in GitHub Desktop.
How to configure port-forward for minikube

How to configure port-forward for minikube

Create minikube-portforward, conf.d and ssl

mkidr minikube-portforward
cd minikube-portforward
mkdir conf.d ssl

Download minikube_portforward.conf and docker-compose.yml

curl -LO https://gist.githubusercontent.com/nhthai2005/4e54a5027f43d5cf0de781e30224eb19/raw/401b269fa1dae9b92806b63e97c098de301bd2af/minikube-portforward.yml
curl -Lo conf.d/minikube_portforward.conf https://gist.githubusercontent.com/nhthai2005/4e54a5027f43d5cf0de781e30224eb19/raw/401b269fa1dae9b92806b63e97c098de301bd2af/minikube_portforward.conf

Copy crt and key files to ssl

Run docker-compose

docker-compose -f minikube-portforward.yml up -d

version: '3'
services:
k8s:
image: nginx:latest
container_name: k8s_proxy
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./ssl:/etc/nginx/ssl
ports:
# minikube cluster
- 192.168.56.73:8080:8080 # Route to 192.168.49.2:8080
- 192.168.56.73:8443:8443 # Route to 192.168.49.2:8443
networks:
- minikube
networks:
minikube:
external: true
server {
listen 8080;
location / {
#proxy_set_header X-Script-Name /;
#proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://192.168.49.2;
proxy_redirect off;
}
}
server {
listen 8443 ssl;
ssl_certificate ssl/nginx-selfsigned.crt;
ssl_certificate_key ssl/nginx-selfsigned.key;
location / {
#proxy_set_header X-Script-Name /;
#proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass https://192.168.49.2;
proxy_redirect off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment