Hello Im learning kubernetes with the minikube. I can access a service via minikubeip:NodePort on the machine where the minikube is running and now I want to access the Service via LAN from other machine. I tried ingress but it didn't work for me.
Deployment file:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: aspnetapp-deployment
labels:
app: aspnetapp
spec:
replicas: 2
selector:
matchLabels:
app: aspnetapp
template:
metadata:
labels:
app: aspnetapp
spec:
containers:
- name: aspnetapp-cn
image: localhost:5000/aspnetapp
ports:
- containerPort: 80
Service file:
---
apiVersion: v1
kind: Service
metadata:
name: aspnetapp-service
spec:
type: NodePort
ports:
- name: http
targetport: 80
port: 80
protocol: TCP
selector:
app: aspnetapp
Ingress file:
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: aspnetapp-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host:
http:
paths:
- path: /aspnetapp
backend:
serviceName: aspnetapp-service
servicePort: 80
To expose your application to LAN with Ubuntu with a
--dockerdriver you can use:$ kubectl port-forward ...Example:
Let's assume that you have an Ubuntu machine with IP:
192.168.0.115.I've created an example using
nginximage:Deployment.yamlAs for the service exposing your
Deploymentyou can either:$ kubectl expose deployment nginx --port=80 --type=NodePortYou can expose your
nginxin two ways:$ kubectl port-forward.Ingresscontroller.Direct access
You can expose your
Servicedirectly without usingIngressby:$ kubectl port-forward --address=0.0.0.0 deployment/nginx 10000:80Dissecting above command:
--address=0.0.0.0- expose outside of localhostdeployment/nginx- resource/resource_name10000:80- port on host machine/port on pod to send the traffic toAfter running above command you should be able to run:
curl 192.168.1.115:10000Command
$ kubectl port-forwardwill generate:Directing the traffic to the
IngresscontrollerIn your example you used
Ingressresource. In this situation you should:Ingressresource (as you did).Ingresscontroller!Ingresscontroller after receiving the traffic will forward it further (to yourServiceand then toPod)To forward the traffic to your
Ingresscontroller run this command:kubectl port-forward --address=0.0.0.0 --namespace=kube-system deployment/ingress-nginx-controller 80:80Dissecting above command once more:
--address=0.0.0.0- expose outside of localhost--namespace=kube-system- namespace that theDeploymentofIngresscontroller resides indeployment/ingress-nginx-controller- resource/resource-name80:80- port on host machine/port on pod to send the traffic toCommand
$ kubectl port-forwardwill generate:I also encourage you to use different
--driverlike for example Virtualbox. You will be able to expose your application without$ kubectl port-forward(NAT).Additional resources: