djb
djb

Reputation: 1674

Minikube running in Docker, and port forwarding

I'm pretty well versed in Docker, but I haven't got Minikube/K8s working yet. I first tried setting up artifactory-oss in helm but failed to connect to the LoadBalancer. Now I'm just trying the basic hello-minikube NodePort setup as a sanity check.

When I do minikube start, it starts up minikube in Docker:

> docker ps
CONTAINER ID   IMAGE                                 COMMAND                  CREATED       STATUS          PORTS                                                                                                                                  NAMES
ebabea521ffe   gcr.io/k8s-minikube/kicbase:v0.0.18   "/usr/local/bin/entr…"   2 weeks ago   Up 36 minutes   127.0.0.1:49167->22/tcp, 127.0.0.1:49166->2376/tcp, 127.0.0.1:49165->5000/tcp, 127.0.0.1:49164->8443/tcp, 127.0.0.1:49163->32443/tcp   minikube

So Minikube only has ports 4916(3/4/5/6/7) open?

So I installed hello-minikube:

> kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
> kubectl expose deployment hello-minikube --type=NodePort --port=8080



> minikube ip
192.168.49.2


> minikube service list
|----------------------|------------------------------------|--------------|---------------------------|
|      NAMESPACE       |                NAME                | TARGET PORT  |            URL            |
|----------------------|------------------------------------|--------------|---------------------------|
| default              | hello-minikube                     |         8080 | http://192.168.49.2:30652 |
| default              | kubernetes                         | No node port |
| kube-system          | ingress-nginx-controller-admission | No node port |
| kube-system          | kube-dns                           | No node port |
| kubernetes-dashboard | dashboard-metrics-scraper          | No node port |
| kubernetes-dashboard | kubernetes-dashboard               | No node port |
|----------------------|------------------------------------|--------------|---------------------------|

> minikube service --url hello-minikube
http://192.168.49.2:30652

I check firewall, and it has the ports I've opened:

> sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources:
  services: dhcpv6-client http https ssh
  ports: 8000-9000/tcp 30000-35000/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

> kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
hello-minikube-6ddfcc9757-hxxmf   1/1     Running   0          40m

> kubectl get svc
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
hello-minikube   NodePort    10.97.233.42   <none>        8080:30652/TCP   36m
kubernetes       ClusterIP   10.96.0.1      <none>        443/TCP          19d

> kubectl describe services hello-minikube
Name:                     hello-minikube
Namespace:                default
Labels:                   app=hello-minikube
Annotations:              <none>
Selector:                 app=hello-minikube
Type:                     NodePort
IP Families:              <none>
IP:                       10.97.233.42
IPs:                      10.97.233.42
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30652/TCP
Endpoints:                172.17.0.6:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

I've tried every IP and port combination, minikube tunnel, and kube proxy and a few other things but I just can't find any port to access this service from another machine. I can't get an 'External-IP'. nmap finds a bunch of ports if i search from the machine itself.

> nmap -p 1-65000 localhost

Starting Nmap 6.40 ( http://nmap.org ) at 2021-04-26 15:16 SAST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0013s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 64971 closed ports
PORT      STATE SERVICE
22/tcp    open  ssh
25/tcp    open  smtp
80/tcp    open  http
111/tcp   open  rpcbind
443/tcp   open  https
631/tcp   open  ipp
3000/tcp  open  ppp
5000/tcp  open  upnp
5050/tcp  open  mmcc
8060/tcp  open  unknown
8080/tcp  open  http-proxy
8082/tcp  open  blackice-alerts
9090/tcp  open  zeus-admin
9093/tcp  open  unknown
9094/tcp  open  unknown
9100/tcp  open  jetdirect
9121/tcp  open  unknown
9168/tcp  open  unknown
9187/tcp  open  unknown
9229/tcp  open  unknown
9236/tcp  open  unknown
33757/tcp open  unknown
35916/tcp open  unknown
41266/tcp open  unknown
49163/tcp open  unknown
49164/tcp open  unknown
49165/tcp open  unknown
49166/tcp open  unknown
49167/tcp open  unknown

But if I scan that machine from another machine on the network:

> nmap -p 1-65000 10.20.2.26

Starting Nmap 6.40 ( http://nmap.org ) at 2021-04-26 15:23 SAST
Nmap scan report for 10.20.2.26
Host is up (0.00032s latency).
Not shown: 58995 filtered ports, 6001 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https
8060/tcp open  unknown

those ports don't seem to be accessible. Any ideas?

-- EDIT 1: The sys admin says only 10.20.x.x IPs will resolve. So 192.168.x.x and 10.96.x.x won't work. So perhaps this --service-cluster-ip-range field is what I'm looking for. I will try it out next.

Upvotes: 3

Views: 11786

Answers (2)

Mikolaj S.
Mikolaj S.

Reputation: 3234

Posted community wiki for better visibility. Feel free to expand it.


Based on this answer.

Seems there is no possibility to access minikube cluster setup with --driver=docker from the other host in the same local network.

The workaround is to use other driver while setting up minikube cluster:

  • --driver=virtualbox (recommended) -> use Bridged Adapter setting
  • --driver=none (potential issues)

For more details (how to setup etc.) please refer to this answer.

Upvotes: 0

Alferd Nobel
Alferd Nobel

Reputation: 3979

I faced a similar issue that I was banging my head upon, this documentation was quite helpful. In my case I was accessing a Jenkins build server running in a Kubernetes cluster via minikube on my Mac OS.

I followed steps to get this port forwarding working:

  1. Confirm the port of your pod :

    kubectl get pod <podname-f5d-48kbr> --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}' -n <namespace-name>

Say the output displays

> 27013             
  1. Forward a local port to a port on the Pod like so :

kubectl port-forward <podname-deployment-f5db75f7-48kbr> 8080:27013 -n <namespace-name>

and that should start the port forwarding, the output like :

Forwarding from 127.0.0.1:8080 -> 27013
Forwarding from [::1]:8080 -> 27013

now access your application on the browser via http://localhost:8080/

Upvotes: 2

Related Questions