I am creating a StatefulSet following this article on Kubernetes.io.
What I want to achieve is the following:
So far I've got the following k8s YAML:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: myservice
spec:
serviceName: myservice
replicas: 3
selector:
matchLabels:
app: myservice
template:
metadata:
labels:
app: myservice
spec:
containers:
- name: myservice
image: myservice/myservice:version
args: ['-root="myservice-0"']
ports:
- containerPort: 2222
Following the K8s article, I thought that the hostname 'myservice-0' would be actually visible to the other pods (as per the "usable stable network identities" section). But this doesn't work.
The command I am executing to run this service is:
kubectl create -f myservice.yml
How could I achieve this in Kubernetes?