Skip to main content
 首页 » 编程设计

git之通过 HTTP 和 SSH 通过 Ingress 访问 Kubernetes Git Container

2024年11月24日24grandyang

我有一个小的 kubernetes (1.3) 集群(基本上是一个节点)并且想在那里安装 gogs。 Gogs 是使用 Helm 来“安装”的。我的掌 Helm chart 中确实有以下模板:

  • 部署(使用镜像 gogs:0.9.97,具有 containerPort 3000 (http) 以及 2222 (ssh)
  • 入口(仅适用于端口 80)
  • 服务(端口 80 (http) 以及 2222 (ssh))

  • http-stuff 配置正确,我可以通过 http 访问容器以及包含的 git-repositories,没有任何问题。现在我也想将 ssh 用于 git 连接。我尝试了 nginx-ingress 的 --tcp-services-configmap 配置,但无济于事。 Ingress Controller 的日志指出,配置的服务没有任何事件端点,我觉得这很奇怪,因为 http 东西正在工作。

    更新

    我刚刚在 DNS 上做了一个 nmap 并且端口 2222 没有打开。这看起来像一个配置问题。端口在容器上是打开的(通过从 ndoe 连接到集群 ip 进行测试)。

    猜测问题出在 Ingress Controller 的日志中,配置的服务没有任何事件的端点。

    我的服务配置是:
    apiVersion: v1 
    kind: Service 
    metadata: 
        name: {{ template "fullname" . }} 
        labels: 
            app: {{ template "fullname" . }} 
    spec: 
        ports: 
           - name: http 
             port: 80 
             targetPort: http 
             protocol: TCP 
           - name: ssh 
             port: 2222 
             targetPort: ssh 
             protocol: TCP 
         selector: 
             app: {{ template "fullname" . }} 
    

    配置映射是:
    apiVersion: v1 
    kind: ConfigMap 
    metadata: 
        name: tcp-configmap-ssh 
    data: 
        2222: "default/{{ template "fullname" . }}:2222" 
    

    请您参考如下方法:

    回答我自己的问题。这个问题更像是配置问题,是我自己的错误造成的。

    基本上我没有发布Nginx-Ingress Resource的ReplicationController。这个缺少端口 2222。所以现在它看起来像:

    apiVersion: v1 
    kind: ReplicationController 
    metadata: 
      name: {{ template "fullname" . }} 
      labels: 
        k8s-app: "{{ .Chart.Name }}" 
        chart: "{{.Chart.Name}}-{{.Chart.Version}}" 
    spec: 
      replicas: 1 
      selector: 
        k8s-app: "{{ .Chart.Name }}" 
      template: 
        metadata: 
          labels: 
            name: {{ template "fullname" . }} 
            k8s-app: "{{ .Chart.Name }}" 
            chart: "{{.Chart.Name}}-{{.Chart.Version}}" 
        spec: 
          terminationGracePeriodSeconds: 60 
          containers: 
          - image: gcr.io/google_containers/nginx-ingress-controller:0.8.3 
            name: "{{ .Chart.Name }}" 
            imagePullPolicy: Always 
            readinessProbe: 
              httpGet: 
                path: /healthz 
                port: 10254 
                scheme: HTTP 
            livenessProbe: 
              httpGet: 
                path: /healthz 
                port: 10254 
                scheme: HTTP 
              initialDelaySeconds: 10 
              timeoutSeconds: 1 
            env: 
              - name: POD_NAME 
                valueFrom: 
                  fieldRef: 
                    fieldPath: metadata.name 
              - name: POD_NAMESPACE 
                valueFrom: 
                  fieldRef: 
                    fieldPath: metadata.namespace 
            ports: 
            - containerPort: 80 
              hostPort: 80 
            # we do need to expose 2222 to be able to access this port via 
            # the tcp-services 
            - containerPort: 2222 
              hostPort: 2222 
            args: 
            - /nginx-ingress-controller 
            - --default-backend-service=$(POD_NAMESPACE)/default-http-backend 
            - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-configmap-ssh