I was trying to setup Service per Pod in stateful set with metacontroller: https://github.com/metacontroller/metacontroller/tree/master/examples/service-per-pod
I was following linked instruction, I was playing with various combination, but I still didn't achieve what is described. Services are not created together with pod.
In this example, I was trying to put service-per-pod-label: "web" against the name of the pod.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx
annotations:
service-per-pod-label: "statefulset.kubernetes.io/pod-name"
service-per-pod-ports: "80:80"
spec:
selector:
matchLabels:
app: nginx
serviceName: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
terminationGracePeriodSeconds: 1
containers:
- name: nginx
image: gcr.io/google_containers/nginx-slim:0.8
ports:
- containerPort: 80
name: web
my metacontroller is up and running
NAME READY STATUS RESTARTS AGE
metacontroller-metacontroller-helm-0 1/1 Running 0 23m
logs from metacontroller: kubectl logs metacontroller-metacontroller-helm-0
{"level":"info","ts":1660492483.489682,"msg":"Configuration information","discovery-interval":20,"cache-flush-interval":1800,"metrics-address":":9999","client-go-qps":5,"client-go-burst":10,"workers":5,"events-qps":0.0033333333333333335,"events-burst":25,"pprofAddr":"0","leader-election":false,"leader-election-resource-lock":"leases","leader-election-namespace":"","leader-election-id":"metacontroller","version":"4.3.4"}
{"level":"info","ts":1660492483.5292923,"msg":"Communication with K8s API server successful"}
{"level":"info","ts":1660492484.7299764,"msg":"Waited for 1.19273971s due to client-side throttling, not priority and fairness, request: GET:https://10.3.0.1:443/apis/authorization.k8s.io/v1?timeout=32s\n"}
{"level":"info","ts":1660492489.1358352,"logger":"controller-runtime.metrics","msg":"Metrics server is starting to listen","addr":":9999"}
{"level":"info","ts":1660492489.1373081,"msg":"Starting EventSource","controller":"composite-metacontroller","source":"kind source: *v1alpha1.CompositeController"}
{"level":"info","ts":1660492489.1373482,"msg":"Starting Controller","controller":"composite-metacontroller"}
{"level":"info","ts":1660492489.1376293,"msg":"Starting EventSource","controller":"decorator-metacontroller","source":"kind source: *v1alpha1.DecoratorController"}
{"level":"info","ts":1660492489.1376536,"msg":"Starting Controller","controller":"decorator-metacontroller"}
{"level":"info","ts":1660492489.1371636,"msg":"Starting server","path":"/metrics","kind":"metrics","addr":"[::]:9999"}
{"level":"info","ts":1660492489.2376945,"msg":"Starting workers","controller":"composite-metacontroller","worker count":1}
{"level":"info","ts":1660492489.2379737,"msg":"Starting workers","controller":"decorator-metacontroller","worker count":1}
{"level":"info","ts":1660492494.7370083,"msg":"Waited for 5.587625994s due to client-side throttling, not priority and fairness, request: GET:https://10.3.0.1:443/apis/networking.k8s.io/v1?timeout=32s\n"}
{"level":"info","ts":1660492510.3382494,"msg":"Waited for 1.165526209s due to client-side throttling, not priority and fairness, request: GET:https://10.3.0.1:443/apis/flowcontrol.apiserver.k8s.io/v1beta2?timeout=32s\n"}
CodePudding user response:
As explained in the documentation, for Kubernetes 1.9 , your service-per-pod-label
should have "statefulset.kubernetes.io/pod-name"
as value:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx
annotations:
service-per-pod-label: "statefulset.kubernetes.io/pod-name"
service-per-pod-ports: "80:80"
spec:
selector:
matchLabels:
app: nginx
serviceName: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
terminationGracePeriodSeconds: 1
containers:
- name: nginx
image: gcr.io/google_containers/nginx-slim:0.8
ports:
- containerPort: 80
name: web
And for earlier versions, you should add the annotation pod-name-label: "pod-name"
for your pod`:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx
annotations:
service-per-pod-label: "pod-name"
service-per-pod-ports: "80:80"
spec:
selector:
matchLabels:
app: nginx
serviceName: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
annotations:
pod-name-label: "pod-name"
spec:
terminationGracePeriodSeconds: 1
containers:
- name: nginx
image: gcr.io/google_containers/nginx-slim:0.8
ports:
- containerPort: 80
name: web
In the two cases, you should use the term pod-name
, and not another value. They use it to know the name they should use for the created services.