Kubernetes - Exposing as a service

3/15/2017

Since rolling update is not a feature supported by statefulsets, thought of experimenting with hybrid pods where the seed nodes would be statefulsets and the other non-seed nodes would be deployments. I was trying out this link as suggested in another question : Statfulsets - akka clustering Is there a way I can expose the seed and the non-seed nodes as the same service so that they can be hit with a single external IP?

-- Nagireddy Hanisha
deployment
kubernetes
service

1 Answer

3/15/2017

That's possible when using labels properly...

For the seed nodes use sth like this:

apiVersion: apps/v1beta1
kind: StatefulSet
...
spec:
  serviceName: akka-seed
  selector:
    matchLabels:
      run: akka-seed
  template:
    metadata:
      labels:
        run: akka-seed
        app: akka

For the worker nodes use sth like this:

apiVersion: apps/v1beta1
kind: Deployment
...
spec:
  template:
    metadata:
      labels:
        run: akka-worker
        app: akka

In the service you can then reference both through:

apiVersion: v1
kind: Service
metadata:
  name: akka
spec:
  ports:
  ...
  selector:
    app: akka

This would select pods from both groups.

-- pagid
Source: StackOverflow