Problem setting NodeAffinity on Headless Service

9/8/2019

Following this tutorial ( https://portworx.com/run-ha-kafka-azure-kubernetes-service/) to setup a Kafka cluster on Azure Kubernetes Service, I am running in an issue deploying the Headless Zookeeper service.

Running this yml with kubectl to deploy the Zookeeper service, I get the error below.

apiVersion: v1
kind: Service
metadata:
  name: zk-headless
nodeAffinity:  labels:
    app: zk-headless
spec:
  ports:
  - port: 2888
    name: server
  - port: 3888
    name: leader-election
  clusterIP: None
  selector:
    app: zk
error converting YAML to JSON: yaml: line 5: mapping values are not allowed in this context

My question is, how do I assign the nodeAffinity value? Should I use this:

requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
-- andy
azure-aks
kubectl
kubernetes

2 Answers

9/9/2019

In addition to Utku's answer - I would recommend using "kubectl explain service" command to see what fields can be added to a kubernetes object like service or deployment or Pod

-- Gowtham
Source: StackOverflow

9/8/2019

Kubernetes Service objects do not have a nodeAffinity field, since Service resources do not run on nodes. In fact, they don't "run" at all - they are rather rules for the networking.

The example provided on the website has a copy-paste error there. It should have been:

apiVersion: v1
kind: Service
metadata:
  name: zk-headless
  labels:
    app: zk-headless
spec:
  ports:
    - port: 2888
      name: server
    - port: 3888
      name: leader-election
  clusterIP: None
  selector:
    app: zk
-- Utku Ă–zdemir
Source: StackOverflow