How to access the application deployed in minikube k8s cluster

3/10/2020

I have installed the minikube, deployed the hello-minikube application and opened the port. Basically I have followed the getting started tutorial at https://kubernetes.io/docs/setup/learning-environment/minikube/#quickstart.

The problem starts when I want to open the URL where the deployed application is running obtained by running minikube service hello-minikube --url.

I get http://172.17.0.7:31198 and that URI cannot be opened, since that IP does not exist locally. Changing it to http://localhost:31198 does not work either (so adding an entry to hosts file won't work I guess).

The application is running, I can query the cluster and obtain the info through http://127.0.0.1:50501/api/v1/namespaces/default/services/hello-minikube:

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "hello-minikube",
    "namespace": "default",
    "selfLink": "/api/v1/namespaces/default/services/hello-minikube",
    "uid": "56845ce6-bbba-45e5-a1b6-d094949438cf",
    "resourceVersion": "1578",
    "creationTimestamp": "2020-03-10T10:33:41Z",
    "labels": {
      "app": "hello-minikube"
    }
  },
  "spec": {
    "ports": [
      {
        "protocol": "TCP",
        "port": 8080,
        "targetPort": 8080,
        "nodePort": 31198
      }
    ],
    "selector": {
      "app": "hello-minikube"
    },
    "clusterIP": "10.108.152.177",
    "type": "NodePort",
    "sessionAffinity": "None",
    "externalTrafficPolicy": "Cluster"
  },
  "status": {
    "loadBalancer": {

    }
  }
}
λ kubectl get services
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
hello-minikube   NodePort    10.108.152.177   <none>        8080:31198/TCP   4h34m
kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP          4h42m

How to access the application deployed in minikube k8s cluster on localhost? Also minikube is running as a docker container on the machine with following ports 32770:2376 32769:8443 32771:22 exposed.

-- Karel Frajták
kubernetes
minikube

1 Answer

3/10/2020

Found the solution in another thread - port forwarding

kubectl port-forward svc/hello-minikube 31191:8080

The first port is port that you will use on your machine (in the browser) and 8080 is the port defined when running the service.

-- Karel Frajták
Source: StackOverflow