Hi,
I am trying to create two stateful set pods and one headless service.
This service has to be used by both the pods. Is that possible? I tried 
different ways but the service gets tied with one pod set and if the service is 
referenced usign label in the second pod set the container keeps terminating.
Could someone help me on this issue.
Below are the yaml files.

Service yml:
====================
kind: Service
metadata:
  name: sample
  namespace: infra
spec:
  
  clusterIP: None
  ports:
    - name: http
      port: 8094
      protocol: TCP
      targetPort: 8094
    - name: ssl
      port: 11207
      protocol: TCP
      targetPort: 11207

  selector:
    run: infrasample

statefulset1.yml:
==================
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: data
  namespace: infra
spec:
  serviceName: "sample"
  replicas: 1
  template:
    metadata:
      labels:
        run: infrasample
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: sample-data
        image: xxxxxx
        ports:
        - name: http-port
          containerPort: 8094
        volumeMounts:
        - name: volume
          mountPath: /opt/app/var
        env:
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.namespace
          - name: NODENAME
            value: "sampledata"
          - name: SERVICE_NAME
            value: "sample"
      volumes:
        - name: volume
          emptyDir: {}

statefulset2.yml:
====================
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: index
  namespace: infra
spec:
  serviceName: "sample"
  replicas: 1
  template:
    metadata:
      labels:
        run: infrasample
    spec:
      terminationGracePeriodSeconds: 0
      containers:
      - name: sample-index
        image: yyy
        ports:
        - name: http-port
          containerPort: 8094
        env:
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.namespace
          - name: NODENAME
            value: "sampleindex"
          - name: SERVICE_NAME
            value: "sample"




-- 
You received this message because you are subscribed to the Google Groups 
"Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to kubernetes-users+unsubscr...@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to