吴晓阳
发布于 2026-02-13 / 2 阅读
0
0

K8s 使用私有仓库拉取镜像

K8s 使用私有仓库拉取镜像

# 通用命令(替换仓库地址、用户名、密码)
kubectl create secret docker-registry my-registry-secret \
  --docker-server=你的私有仓库地址(比如 https://harbor.example.com) \
  --docker-username=私有仓库用户名 \
  --docker-password=私有仓库密码 \
  --docker-email=你的邮箱(可选) \
    --namespace=default  # 密钥的命名空间,需和部署的Pod同命名空间


apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-dotnet-app
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-dotnet-app
  template:
    metadata:
      labels:
        app: my-dotnet-app
    spec:
      # 关键1:引用镜像拉取密钥
      imagePullSecrets:
        - name: my-registry-secret  # 和步骤1创建的密钥名一致
      containers:
      - name: my-dotnet-app
        # 关键2:私有仓库的完整镜像地址
        image: harbor.example.com/myapp:v1.0  # 替换为你的私有镜像地址
        ports:
        - containerPort: 80

评论