在反向代理后面运行goharbor

时间:2020-04-16 12:53:35

标签: apache kubernetes docker-registry harbor

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

在终端上,我可以将舵图推到http://harbor.domain/chartrepo/

我能够登录

docker login harbor.domain:80

并推送到注册表。

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

我通过更改values.yaml

使用Harbor-Helm图表重新安装了
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>

2 个答案:

答案 0 :(得分:0)

您似乎无法授权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}}

答案 1 :(得分:0)

我的第一个问题是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>
相关问题