How does StatefulSet spec in Kubernetes assigns the hostname to each container in case we set hostNetwork: true
? I have the following spec (similar):
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: abc
spec:
serviceName: abc
replicas: 2
template:
metadata:
labels:
app: abc
spec:
hostNetwork: true
#hostame: test
terminationGracePeriodSeconds: 10
containers:
- name: abc
image: abc.xyz.com:9001/abc:01.00.00.00
ports:
- name: api-port
containerPort: 9000
hostPort: 9000
readinessProbe:
httpGet:
path: /api
port: api-port
scheme: HTTPS
Now after running the kubectl create
command, I see that the first container when comes up picks the hostname of the host since we have specified hostNetwork: true
, but the second container when comes up has hostname something like abc-0.abc.default.svc.cluster.local
.
Also, the only service running is the Kubernetes service. I didn't create abc service myself.
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 10.96.0.1 <none> 443/TCP 1d
It should create only one pod per node, I tested below in my 1.8 cluster, its created one pod per node with correct pod hostname name (same as node name). it will not create any service we need to create one.
your cluster is version 1.7.3, it may be bug that's why its creating hostname incorrectly.
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: abc
spec:
serviceName: abc
replicas: 3
template:
metadata:
labels:
app: abc
spec:
hostNetwork: true
#hostame: test
terminationGracePeriodSeconds: 10
containers:
- name: sfgtools
image: sfgroups/alphine_nettools
ports:
- name: api-port
containerPort: 80
hostPort: 80