Kubernetes local port for deployment in Minikube

3/3/2017

I'm trying to expose my Deployment to a port which I can access through my local computer via Minikube.

I have tried two YAML configurations (one a load balancer, one just a service exposing a port). I: http://pastebin.com/gL5ZBZg7

apiVersion: v1
kind: Service
metadata:
  name: bot
labels:
    app: bot
spec:
  type: LoadBalancer
  ports:
  - port: 8000
    targetPort: 8000
    protocol: TCP
  selector:
    app: bot

II: http://pastebin.com/sSuyhzC5

apiVersion: v1
kind: Service
metadata:
  name: bot
  labels:
    app: bot
spec:
  ports:
  - port: 8000
    targetPort: 8000
    protocol: TCP
  selector:
    app: bot

The deployment and the docker container image both expose port 8000, and the Pod is tagged with app:bot.

The first results in a service with a port which never finishes, and the external IP never gets assigned. The second results in a port of bot:8000 TCP, bot:0 TCP in my dashboard and when I try "minikube service bot" nothing happens. The same happens if I type in "kubectl expose service bot".

I am on Mac OS X.

How can I set this up properly?

-- skunkwerk
kubernetes
minikube

2 Answers

3/6/2017

Minikube now has the service command to access a service.

Use kubectl service <myservice>.

That will give you a URL which you can use to talk to the service.

-- adam.sandor
Source: StackOverflow

3/4/2017

The LoadBalancer service is meant for Cloud providers and not really relevant for minikube.

From the documentation:

On cloud providers which support external load balancers, setting the type field to "LoadBalancer" will provision a load balancer for your Service.

Using a Service of type NodePort (see documentation) as mentioned in the Networking part of the minikube documentation is the intended way of exposing services on minikube.

So your configuration should look like this:

apiVersion: v1
kind: Service
metadata:
  name: bot
  labels:
    app: bot
spec:
  type: NodePort
  ports:
  - port: 8000
    targetPort: 8000
    nodePort: 30356
    protocol: TCP
  selector:
    app: bot

And access your application through:

> IP=$(minikube ip)
> curl "http://$IP:30356"

Hope that helps.

-- pagid
Source: StackOverflow