【问题标题】:running goharbor behind a reverse proxy在反向代理后面运行 goharbor
【发布时间】:2023-03-25 09:50:01
【问题描述】:

您好,我有 harbor 使用 nginx ingress 在 http://harbor.domain 下完美运行,我使用 Harbor-helm 图表安装。

在终端上我可以将 helmcharts 推送到http://harbor.domain/chartrepo/

我可以登录

docker login harbor.domain:80

并推送到注册表。

我的挑战是我希望通过 apache 代理访问港口,例如

我通过更改values.yaml使用harbor-helm chart重新安装

externalURL: https://example.com

所以我在/etc/apache2/sites-available/example-le-ssl.conf 添加了以下内容

    # helmcharts 
    <Location "/chartrepo/"> 
          ProxyPass "http://harbor.domain/chartrepo/"
          ProxyPassReverse "http://harbor.domain/chartrepo/"
    </Location>

    # harbor 
    <Location "/harbor"> 
          ProxyPass "http://harbor.domain/harbor"
          ProxyPassReverse "http://harbor.domain/harbor"
    </Location>

    # registry 
    <Location "/v2"> 
          ProxyPass "http://harbor.domain/v2"
          ProxyPassReverse "http://harbor.domain/v2"
    </Location>

不幸的是,如果我这样做了docker login example.com docker 登录返回

Error response from daemon: login attempt to https://example.com/v2/ failed with status: 503 Service Unavailable

我在注册表日志中收到以下错误

error authorizing context: authorization token required

关于我缺少什么的任何想法?

尝试推送图表也失败了。

helm push --username='username' --password='password' demo-chart.tgz https://example.com/chartrepo/

错误是

Error: 404: could not properly parse response JSON: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at example.com Port 443</address>
</body></html>

【问题讨论】:

    标签: apache kubernetes docker-registry harbor


    【解决方案1】:

    我的第一个问题是 apache 如何处理到 https 后端的代理,这里解释了 how to configure apache server to talk to HTTPS backend server?

    我添加到我的虚拟主机/etc/apache2/sites-available/example-le-ssl.conf

        SSLProxyEngine on
        SSLProxyVerify none
        SSLProxyCheckPeerCN off
        SSLProxyCheckPeerName off
        SSLProxyCheckPeerExpire off
        <Location "/v2"> 
              ProxyPass "http://harbor.domain/v2"
              ProxyPassReverse "http://harbor.domain/v2"
        </Location>
        <Location "/service/">
              # RequestHeader set X-Forwarded-Proto "https"
              ProxyPass "http://harbor.domain/service/"
              ProxyPassReverse "http://harbor.domain/service/"
        </Location>
    

    【讨论】:

      【解决方案2】:

      您似乎无法授权 docker 注册表。您可以将变量添加到默认服务帐户,或者我们可以创建 docker 注册表密钥并将其作为 imagepullsecret 添加到部署中。

      如果你想从 imagepullsecret 做这个,你可以创建一个模板助手,比如

      /* image pull secret */
      {{- define "imagePullSecret" }}
      {{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageCredentials.registry (printf "%s:%s" .Values.imageCredentials.username .Values.imageCredentials.password | b64enc) | b64enc }}
      {{- end }}
      

      然后您可以在部署文件中使用它,例如

      imagePullSecrets:
            - name: {{.Values.imageCredentials.secretName}}
      

      整个文件可能看起来像

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: {{ .Values.appName }}
        namespace: {{ .Values.namespace }}
      spec:
        selector:
          matchLabels:
            app: {{ .Values.appName }}
        replicas: {{ .Values.replicaCount }}
        template:
          metadata:
            labels:
              app: {{ .Values.appName }}
          spec:
            containers:
            - name: {{ .Values.appName }}
              image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              {{- if .Values.hasSecretVolume }}
              volumeMounts:
              - name: {{ .Values.appName }}-volume-sec
                mountPath: {{ .Values.secretVolumeMountPath }}
              {{- end}}
              {{- if or .Values.env.configMap .Values.env.secrets }}
              envFrom:
              {{- if .Values.env.configMap }}
              - configMapRef:
                  name: {{ .Values.appName }}-env-configmap
              {{- end }}
              {{- if .Values.env.secrets }}
              - secretRef:
                  name: {{ .Values.appName }}-env-secret
              {{- end }}
              {{- end }}
              ports:
              - containerPort: {{ .Values.containerPort }}
                protocol: TCP
      {{- if .Values.springContainerHealthChecks}}
      {{ toYaml .Values.springContainerHealthChecks | indent 8 }}
      {{- end}}
            {{- if .Values.hasSecretVolume }}
            volumes:
            - name: {{ .Values.appName }}-volume-sec
              secret:
                secretName: {{ .Values.appName }}-volume-sec
            {{- end}}
            {{- if .Values.imageCredentials}}
            imagePullSecrets:
            - name: {{.Values.imageCredentials.secretName}}
            {{- end}}
      
      

      【讨论】:

      • 问题不是凭证,因为它在harbor.domain下工作。我最终想通了,我会发布更长的答案
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      • 2011-11-10
      • 2016-05-05
      • 1970-01-01
      相关资源
      最近更新 更多