Minikube unable to expose service with yaml

11/15/2017

Trying to run a local registry. I have the following configuration:

Deployment:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: registry
  labels:
    app: registry
    role: registry
spec:
  replicas: 1
  selector:
    matchLabels:
      app: registry
  template:
    metadata:
      labels:
        app: registry
    spec:
      containers:
      - name: registry
        image: registry:latest
        ports:
        - containerPort: 5000
        volumeMounts:
          - mountPath: '/registry'
            name: registry-volume
      volumes:
      - name: registry-volume
        hostPath:
          path: '/data'
          type: Directory

Service:

apiVersion: v1
kind: Service
metadata:
  name: registry
  namespace: default
  labels:
    app: registry
spec:
  selector:
    role: registry
  type: NodePort
  ports:
    - name: registry
      nodePort: 31001
      port: 5000
      protocol: TCP

It all works well when I create deployment/service. kubectl shows status as Running for both service and deployment:

NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/registry   1         1         1            1           30m

NAME                     DESIRED   CURRENT   READY     AGE
rs/registry-6549cbc974   1         1         1         30m

NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/registry   1         1         1            1           30m

NAME                     DESIRED   CURRENT   READY     AGE
rs/registry-6549cbc974   1         1         1         30m

NAME                           READY     STATUS    RESTARTS   AGE
po/registry-6549cbc974-mmqpj   1/1       Running   0          30m

NAME             TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
svc/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP          37m
svc/registry     NodePort    10.0.0.6     <none>        5000:31001/TCP   7m

However, when I try to get external IP for service using: minikube service registry --url, it times-out/fails: Waiting, endpoint for service is not ready yet....

When I delete the service (keeping deployment intact), and manually expose the deployment using kubectl expose deployment registry --type=NodePort, I am able to get it working.

Minikube log can be found here.

-- Jaskaranbir Singh
kubernetes
minikube

1 Answer

11/15/2017

You need to specify the correct spec.selector in registry service manifest:

apiVersion: v1
kind: Service
metadata:
  name: registry
  namespace: default
  labels:
    app: registry
spec:
  selector:
    app: registry
  type: NodePort
  ports:
    - name: registry
      nodePort: 31001
      port: 5000
      protocol: TCP

Now registry service correctly points to the registry pod:

$ kubectl get endpoints
NAME         ENDPOINTS         AGE
kubernetes   10.0.2.15:8443    14m
registry     172.17.0.4:5000   4s

And you can get external url as well:

$ minikube service registry --url
http://192.168.99.106:31001
-- nickgryg
Source: StackOverflow