Kubernetes 使用镜像拉取秘密创建 StatefulSet?

Tho*_*mas 0 kubernetes kubernetes-helm

对于 Kubernetes 部署,我们可以指定 imagePullSecrets 以允许它从我们的私有注册表中提取 Docker 镜像。但据我所知,StatefulSet 不支持这个?

如何向我的 StatefulSet 提供 pullsecret?

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
  namespace: {{ .Values.namespace }}
  labels:
    app: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  serviceName: redis-service
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: redis
    spec:
      terminationGracePeriodSeconds: 10
      # imagePullSecrets not valid here for StatefulSet :-(
      containers:
        - image: {{ .Values.image }}
Run Code Online (Sandbox Code Playgroud)

Dae*_*ark 7

StatefulSet支持imagePullSecrets. 您可以按如下方式检查。

$ kubectl explain statefulset.spec.template.spec --api-version apps/v1
:
   imagePullSecrets <[]Object>
     ImagePullSecrets is an optional list of references to secrets in the same
     namespace to use for pulling any of the images used by this PodSpec. If
     specified, these secrets will be passed to individual puller
     implementations for them to use. For example, in the case of docker, only
     DockerConfig type secrets are honored. More info:
     https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
:
Run Code Online (Sandbox Code Playgroud)

例如,您可以StatefulSet先尝试在您的集群中是否可以创建以下示例。

$ kubectl create -f - <<EOF
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      imagePullSecrets:
      - name: YOUR-PULL-SECRET-NAME
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
EOF

$ kubectl get pod web-0 -o yaml | \
  grep -E '^[[:space:]]+imagePullSecrets:' -A1
  imagePullSecrets:
  - name: YOUR-PULL-SECRET-NAME
Run Code Online (Sandbox Code Playgroud)