I am trying to deploy a simple nginx
deployment for learning purposes and created the following resources. I am running this setup in macos
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- host: nginx.jananath.site
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80
Everything works fine ONLY if I try curl -kv http://nginx.jananath.site
inside the minikube docker container after accessing it through minikube ssh
But What I want to do is, without ssh-ing into the minikube container, I need to access the same application locally (in the host machine where the minikube is running)
I tried the following steps but it doesn’t work.
Get the minikube
IP:
minikube ip
map it to the hostname in the local machine (where the minikube is running) at /etc/hosts
<MINIKUBE-IP> nginx.jananath.site
But still doesn’t work. Can someone help me on this?
Note: I don’t want the service nginx
to be a NodePort but a ClusterIP as mentioned in the above service yaml.
Thank you,
Best Regards
2
Answers
If you use the docker driver, start minikube with
--ports 80:80
it will map the localhost port to the minikube node.If you use macos with hyperkit driver it is
--hyperkit-vsock-ports=
Did you try the port forwarding?
kubectl port-forward service/nginx 8080:80
This will forward port 8080 on your local machine to port 80 of the nginx service.
You can access your application via http://localhost:8080.