【问题标题】:How to upload and download docker images using nexus registry/repository?如何使用 nexus registry/repository 上传和下载 docker 镜像?
【发布时间】:2022-12-23 04:06:34
【问题描述】:

我能够使用 jenkins 管道发布 Docker 映像,但不能从 nexus 中提取 docker 映像。我使用 kaniko 构建映像。

部署.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: test-app
  name: test-app
  namespace: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-app
  template:
    metadata:
      labels:
        app: test-app
    spec:
      hostNetwork: false
      containers:
        - name: test-app
          image: ip_adress/demo:0.1.0
          imagePullPolicy: Always
          resources:
            limits: {}
      imagePullSecrets:
        - name: registrypullsecret

服务.yml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: test-app
  name: test-app-service
  namespace: jenkins
spec:
  ports:
    - nodePort: 32225
      port: 8081
      protocol: TCP
      targetPort: 8081
  selector:
    app: test-app
  type: NodePort

Jenkins 流水线主脚本

stage ('Build Image'){
        container('kaniko'){
                    script {
            sh '''
            /kaniko/executor --dockerfile `pwd`/Dockerfile --context `pwd` --destination="$ip_adress:8082/demo:0.1.0" --insecure --skip-tls-verify
             '''
          }

stage('Kubernetes Deployment'){
            container('kubectl'){
                 withKubeConfig([credentialsId: 'kube-config', namespace:'jenkins']){
                     sh 'kubectl get pods'
                     sh 'kubectl apply -f deployment.yml'
                     sh 'kubectl apply -f service.yml'
                 }

我创建了一个 Spring boot Java 应用程序的 dockerfile。我已使用 Jenkins 管道将图像发送到 Nexus,但我无法部署它。

kubectl get pod -n jenkins

测试应用程序-... 0/1 ImagePullBackOff

kubectl describe pod test-app-.....

来自服务器的错误 (NotFound):pods“test-app-..”未找到

docker pull $ip_address:8081/repository/docker-releases/demo:0.1.0```

来自守护程序的错误响应:获取“https://$ip_adress/v2/”:http:server 向 HTTPS 客户端提供 HTTP 响应

ip地址:私有ip地址

如何作为 http 发送?

【问题讨论】:

    标签: docker kubernetes jenkins-pipeline nexus3 kaniko


    【解决方案1】:

    首先尝试编辑 /etc/containerd/config.toml 并像这样添加注册表 ip:port { "insecure-registries": ["172.16.4.93:5000"] }

    如果仍然存在问题,请将您的 nexus 注册表凭据添加到 yaml kubernetes 文件中,如下面的链接 https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

    【讨论】:

    • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以在in the help center找到更多关于如何写出好的答案的信息。
    【解决方案2】:

    如果我们想使用私有注册表来拉取 kubernetes 中的图像,我们需要将注册表端点和凭证配置为机密,并在 pod 部署配置中使用它。

    注意:secrets 必须与 Pod 位于相同的命名空间中

    参考这个 official k8 document 了解更多关于在 Kubernetes 中配置私有注册表的细节

    在您的情况下,您使用的是秘密registrypullsecret.所以再检查一次秘密是否配置正确。如果没有,请尝试按照上述文档进行操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-01
      • 2014-11-28
      • 2019-11-13
      • 2017-04-27
      • 2020-12-04
      • 1970-01-01
      • 2019-02-14
      • 1970-01-01
      相关资源
      最近更新 更多