kubernetes - Kubernetes 使用图像拉取密钥创建 StatefulSet?
问题描述
对于 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 }}
解决方案
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
:
例如,您可以尝试以下示例是否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
推荐阅读
- websphere-8 - 在进行从 8.5.5.0 到 8.5.5.13 的修订包升级失败并出现 CRIMA1161E 错误
- symfony - 使用匿名令牌填充 TokenStorage - SF4
- mysql - 在每次使用触发器插入 MySQL 5.6 中的目标表后,尝试将 Last updated row_id 从源表拉到另一个表
- python - 如何用 numpy 创建对角矩阵?
- ruby-on-rails - ruby on rails 中的 Stripe SCA 结帐
- java - 如何实现我的代码以发送密码重置链接?
- r - 针对 Redshift 的 pSQL 查询在 DataGrip 中有效,但在通过 R 运行时被 WLM 中止操作取消?
- flutter - Flutter 中的圆作为背景
- graphql - 为联合服务 apollo GraphQL 中的架构更改自动重新加载网关
- python - 相当于python中的一些JS代码