将序号为0的Kuberentes StatefulSet Pod退出服务?

时间:2018-12-06 07:28:53

标签: kubernetes load-balancing

我正在将应用程序作为带有2个Pod的StatefulSet运行。我最近发现了一个问题,需要清除磁盘上的某些内容并重新启动应用程序。

我希望通过至少运行一个Pod来最大程度地减少对客户的影响。

这对于pod-1来说是微不足道的,因为我可以按比例缩小并进行有需要的操作并按比例缩放备份。但是,如果pod-1未运行,则StatefulSet将不会运行pod-0,因此,我不能只是将pod-0从服务中删除。

我知道,也许有一种方法可以重新标记Pod,以将pod-0从服务中删除。不幸的是,这不是一个选择,因为它将旋转一个新的pod-0(据我了解)。

是否存在通过服务公开选择的Pod或将其从服务端点中删除并重新添加的方法?

规格文件示例

spec:
  podManagementPolicy: OrderedReady
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: myapp
  serviceName: myapp-headless
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: myapp
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: app
                operator: NotIn
                values:
                - confluence
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - myapp
            topologyKey: kubernetes.io/hostname
      containers:
      - env:
        - name: JVM_MINIMUM_MEMORY
          value: 4g
        - name: JVM_MAXIMUM_MEMORY
          value: 4g
        - name: CATALINA_CONNECTOR_PROXYNAME
          value: myapp.dev.example.com
        - name: CATALINA_CONNECTOR_PROXYPORT
          value: "443"
        - name: CATALINA_CONNECTOR_SCHEME
          value: https
        - name: CATALINA_CONNECTOR_SECURE
          value: "true"
        - name: CLUSTER
          value: "true"
        - name: CLUSTER_DOMAIN
          value: myapp-headless.proteus.svc.cluster.local
        - name: CROWD_SSO
          value: "false"
        - name: CROWD_APP_NAME
          value: myapp
        - name: CROWD_APP_PASSWORD
          value: xxx
        - name: CROWD_BASEURL
          value: https://crowd.dev.example.com
        image: xxx
        imagePullPolicy: IfNotPresent
        name: myapp
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        - containerPort: 40001
          name: ehcache
          protocol: TCP
        resources:
          limits:
            memory: 8Gi
          requests:
            memory: 4Gi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /var/vendor/application-data/myapp-home
          name: home
        - mountPath: /var/vendor/application-data/myapp-home/shared
          name: shared
        - mountPath: /var/vendor/application-data/myapp-home/dbconfig.xml
          name: myapp-db-config
          subPath: dbconfig.xml
        - mountPath: /opt/vendor/myapp/logs
          name: tomcat-logs
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: ecr
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        fsGroup: 2
        runAsUser: 2
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          defaultMode: 420
          name: myapp-dbconfig-cm
        name: myapp-db-config
      - name: shared
        persistentVolumeClaim:
          claimName: myapp-shared
      - emptyDir: {}
        name: tomcat-logs
  updateStrategy:
    type: OnDelete
  volumeClaimTemplates:
  - metadata:
      creationTimestamp: null
      name: home
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
      storageClassName: myapp-home-volume

0 个答案:

没有答案