I am running my minikube as docker image.
I am trying to expose my service to outside world using Nodeport.
This is my yaml file.
apiVersion: apps/v1
kind: Deployment
metadata:
name: docker-hello-world
labels:
app: docker-hello-world
spec:
selector:
matchLabels:
app: docker-hello-world
replicas: 3
template:
metadata:
labels:
app: docker-hello-world
spec:
containers:
- name: docker-hello-world
image: scottsbaldwin/docker-hello-world:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: docker-hello-world-svc
spec:
selector:
app: docker-hello-world
ports:
- port: 8088
targetPort: 80
type: NodePort
Searched a lot about nodePort that we require node ip to access the service.
I am able to access my service using minikube service docker-hello-world-svc –url
which gives me url to access the service http://127.0.0.1:52526
but here port number is different then the nodePort.
My service is successful running .
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
docker-hello-world-svc NodePort 10.109.146.181 <none> 8088:30934/TCP 65m
i want to access my service from outside the cluster using Nodeport but my nodes does not have any external ip
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready control-plane 5h9m v1.24.3 192.168.49.2 <none> Ubuntu 20.04.4 LTS 5.10.104-linuxkit docker://20.10.17
already read out that i need ingress controller to access service but i wanna test it using nodePort .
Any work around so i can access my service using only nodePort running inside the minikube which is running as docker image?
Status of minikube does not show kubectl
>>minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
2
Answers
You don’t need an external IP when using NodePort, you can use
minikube ip
to get the minikube node address, and then connect to the respectivenodePort
:Another alternative is to use a
LoadBalancer
service, and useminikube tunnel
to connect to it using the internal port:Notes:
EXTERNAL-IP
after runningminikube tunnel
in a separate terminal (it’s a foreground process)You can use port forwarding with kubeclt. kubectl port-forward allows using resource name, such as a pod name, to select a matching pod to port forward to.