Image Credentials¶
Der Image Credentials-Helper erstellt Docker Registry Secrets für das Pullen von Container Images aus privaten Registries.
Übersicht¶
Image Credentials (auch Docker Registry Secrets genannt) ermöglichen Kubernetes, Container Images aus privaten Registries zu pullen. Der Helper erstellt Secrets vom Typ kubernetes.io/dockerconfigjson.
Basis-Konfiguration¶
imageCredentials:
- name: registry-secret
namespace: production
registry: https://registry.example.com
username: "my-username"
accessToken: "my-secret-token"
Unterstützte Registries¶
Docker Hub¶
imageCredentials:
- name: dockerhub
namespace: production
registry: https://index.docker.io/v1/
username: "dockerhub-user"
accessToken: "dckr_pat_xxxxx"
GitHub Container Registry¶
imageCredentials:
- name: ghcr
namespace: production
registry: https://ghcr.io
username: "github-user"
accessToken: "ghp_xxxxx"
GitLab Container Registry¶
imageCredentials:
- name: gitlab-registry
namespace: production
registry: https://registry.gitlab.com
username: "gitlab-ci-token"
accessToken: "glpat-xxxxx"
Azure Container Registry¶
imageCredentials:
- name: acr
namespace: production
registry: https://myregistry.azurecr.io
username: "service-principal-id"
accessToken: "service-principal-secret"
AWS ECR¶
imageCredentials:
- name: ecr
namespace: production
registry: https://123456789.dkr.ecr.eu-central-1.amazonaws.com
username: "AWS"
accessToken: "ecr-auth-token"
ECR Token-Rotation
AWS ECR Tokens sind nur 12 Stunden gültig. Für Production empfehlen wir den ECR Credential Helper oder External Secrets Operator.
Harbor¶
imageCredentials:
- name: harbor
namespace: production
registry: https://harbor.example.com
username: "robot$myproject+pull"
accessToken: "robot-token"
Mehrere Registries¶
imageCredentials:
# Interne Registry
- name: internal-registry
namespace: production
registry: https://registry.internal.company.com
username: "ci-user"
accessToken: "internal-token"
# Docker Hub für Base Images
- name: dockerhub
namespace: production
registry: https://index.docker.io/v1/
username: "company-dockerhub"
accessToken: "dckr_pat_xxxxx"
# GitHub für Open Source
- name: ghcr
namespace: production
registry: https://ghcr.io
username: "github-user"
accessToken: "ghp_xxxxx"
Mehrere Namespaces¶
Für Multi-Namespace-Deployments erstellen Sie das Secret in jedem Namespace:
imageCredentials:
- name: registry-secret
namespace: production
registry: https://registry.example.com
username: "ci-user"
accessToken: "secret-token"
- name: registry-secret
namespace: staging
registry: https://registry.example.com
username: "ci-user"
accessToken: "secret-token"
- name: registry-secret
namespace: development
registry: https://registry.example.com
username: "ci-user"
accessToken: "secret-token"
Verwendung in Deployments¶
Im Chart-Modus¶
chart:
enabled: true
container:
image: registry.example.com/myapp:latest
imagePullSecrets:
- name: registry-secret
Mit RBAC Helper¶
myapp:
imageCredentials:
- name: registry-secret
namespace: production
registry: https://registry.example.com
username: "ci-user"
accessToken: "secret-token"
rbac:
enabled: true
imagePullSecrets:
- name: registry-secret
Vollständiges Beispiel¶
# Chart.yaml
apiVersion: v2
name: my-app
version: 1.0.0
dependencies:
- name: ohmyhelm
alias: app
repository: https://gitlab.com/ayedocloudsolutions/ohmyhelm
version: 1.13.0
# values.yaml
app:
# Registry Credentials
imageCredentials:
- name: company-registry
namespace: production
registry: https://cargo.company.cloud
username: "robot+ci"
accessToken: "{{ .Values.registryToken }}"
# Namespace erstellen
namespaces:
setPreInstallHook: true
spaces:
- name: production
# Deployment
chart:
enabled: true
fullnameOverride: "my-app"
container:
image: cargo.company.cloud/apps/my-app:v1.0.0
ports:
- name: http
containerPort: 8080
imagePullSecrets:
- name: company-registry
Best Practices¶
- Robot-Accounts verwenden - Erstellen Sie dedizierte Pull-Accounts statt persönliche Credentials
- Minimale Berechtigungen - Robot-Accounts sollten nur Pull-Rechte haben
- Token-Rotation - Rotieren Sie Tokens regelmäßig
- Externe Secret-Manager - Für Production verwenden Sie External Secrets Operator
- Namespace-Isolation - Erstellen Sie separate Secrets pro Namespace
Troubleshooting¶
ImagePullBackOff¶
# Secret prüfen
kubectl get secret registry-secret -n production -o yaml
# Decoded credentials prüfen
kubectl get secret registry-secret -n production -o jsonpath='{.data.\.dockerconfigjson}' | base64 -d
# Pod Events prüfen
kubectl describe pod <pod-name> -n production
Authentication Failed¶
Stellen Sie sicher, dass:
- Die Registry-URL korrekt ist (mit
https://) - Username und Token stimmen
- Der Token nicht abgelaufen ist
- Der Account Pull-Rechte für das Repository hat