Kubernetes Statefulsets traffic issue

Viewed 22

I am trying to deploy 3 replicas using statefulsets.

Now, I have three pods:

statefulset-test-0
statefulset-test-1
statefulset-test-2

Then, I need to use the following to rolling update:

kubectl rollout restart statefulsets/statefulset-test 

it will stop statefulset-test-2 pod and create a new statefulset-test-2 pod, then it will stop statefulset-test-1.

At this point, statefulset-test-2 is running the new image, statefulset-test-1 has been stopped so it can not accept requests, and statefulset-test-0 is running the old image.

I was wondering how the k8s handles the request to those pods. Is the k8s send the request to test-0 and test-2 randomly or do they send the request to the new pod?

here is my yaml:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: statefulset-test
  labels:
    app: statefulset-test
spec:
  minReadySeconds: 20
  serviceName: "statefulset-test"
  updateStrategy:
    type: RollingUpdate
  replicas: 3
  selector:
    matchLabels:
      app: statefulset-test
  template:
    metadata:
      labels:
        app: statefulset-test
    spec:
      containers:
      - name: statefulset-test
        image: ..
        imagePullPolicy: Always
        ports:
        - containerPort: 123
        - containerPort: 456
        livenessProbe:
          httpGet:
            path: /api/Health
            port: 123
          initialDelaySeconds: 180
          periodSeconds: 80
          timeoutSeconds: 20
          failureThreshold: 2
        readinessProbe:
          httpGet:
            path: /api/Health
            port: 123
          initialDelaySeconds: 20
          periodSeconds: 5
          successThreshold: 1
---
apiVersion: v1
kind: Service
metadata:
  name: statefulset-service
spec:
  type: NodePort
  selector:
    app: statefulset-test
  ports:
    - name: statefulset-main
      protocol: TCP
      port: 123
      targetPort: 123
      nodePort: 678
    - name : statefulset-grpc
      protocol: TCP
      port: 456
      targetPort: 456
      nodePort: 679
0 Answers
Related