将Kubernetes的音量限制为单个Pod

时间:2019-02-26 03:22:29

标签: kubernetes scylla

我有一个带有附加卷的Scylla数据库的Kubernetes部署。它具有一个副本,其清单类似于以下内容:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: scylla
  labels:
    app: myapp
    role: scylla
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
      role: scylla
  template:
    metadata:
      labels:
        app: myapp
        role: scylla
    spec:
      containers:
        - name: scylla
          image: scylladb/scylla
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /var/lib/scylla/data
              name: scylladb
      volumes:
        - name: scylladb
          hostPath:
            path: /var/myapp/scylla/
            type: DirectoryOrCreate

当我执行更新时,它将终止旧的pod并在旧的pod停止之前启动新的pod。这将导致新Pod上的数据库失败,因为它无法访问卷中存储的数据库文件(因为旧Pod仍在使用它)。我如何才能做到一次只有一个吊舱使用该卷? (短暂的停机时间还可以)

1 个答案:

答案 0 :(得分:3)

您可以在部署中使用重新创建策略来执行此操作。在创建新的Pod之前,这将杀死所有现有Pod。参考:Kubernetes doc。因此,这将导致一些停机时间。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: scylla
  labels:
    app: myapp
    role: scylla
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
      role: scylla
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: myapp
        role: scylla
    spec:
      containers:
        - name: scylla
          image: scylladb/scylla
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /var/lib/scylla/data
              name: scylladb
      volumes:
        - name: scylladb
          hostPath:
            path: /var/myapp/scylla/
            type: DirectoryOrCreate