0

我正在努力将我们现有的 docker 容器迁移到 openshift 中,并且在尝试将我们的 2 个容器放入一个 pod 时遇到了问题。我们将 Spring Cloud Config Server 用于我们的服务,并带有 Gitea 后端。我想将它们放在一个 pod 中,以便 java 服务器和 git 服务器总是捆绑在一起。

我可以通过关联的路由单独访问每个容器,但配置服务器无法访问 git 服务器,反之亦然。当配置服务器尝试克隆 git 存储库时,我得到 404。我尝试过使用 gitea-${INSTANCE_IDENTIFIER}(INSTANCE_IDENTIFIER 只是一个生成的值,可以一目了然地将所有对象联系在一起)、gitea-${INSTANCE_IDENTIFIER}.myproject.svc 和 gitea-${INSTANCE_IDENTIFIER}.myproject .svc.cluster.local,以及创建的路由的完整 url,但没有任何效果。

这是我的模板,为了安全起见,删除了一些东西(...):

apiVersion: v1
kind: Template
metadata:
  name: configuration-template
  annotations:
    description: 'Configuration containers template'
    iconClass: 'fa fa-gear'
    tags: 'git, Spring Cloud Configuration'
objects:
  - apiVersion: v1
    kind: ConfigMap
    metadata:
      name: 'gitea-config-${INSTANCE_IDENTIFIER}'
      labels:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
        gitea: '${GITEA_VERSION}'
        configuration: '${CONFIGURATION_VERSION}'
    data:
      local-docker.ini: |
        APP_NAME = Git Server
        RUN_USER = git
        RUN_MODE = prod

        [repository]
        ROOT = /home/git/data/git/repositories

        [repository.upload]
        TEMP_PATH = /home/git/data/gitea/uploads

        [server]
        APP_DATA_PATH    = /home/git/data/gitea
        HTTP_PORT        = 8443
        DISABLE_SSH      = true
        SSH_PORT         = 22
        LFS_START_SERVER = false
        OFFLINE_MODE     = false
        PROTOCOL     = https
        CERT_FILE    = /var/run/secrets/service-cert/tls.crt
        KEY_FILE     = /var/run/secrets/service-cert/tls.key
        REDIRECT_OTHER_PORT = true
        PORT_TO_REDIRECT = 8080

        [database]
        PATH     = /home/git/data/gitea/gitea.db
        DB_TYPE  = sqlite3
        NAME     = gitea
        USER     = gitea
        PASSWD   = XXXX

        [session]
        PROVIDER_CONFIG = /home/git/data/gitea/sessions
        PROVIDER        = file

        [picture]
        AVATAR_UPLOAD_PATH      = /home/git/data/gitea/avatars
        DISABLE_GRAVATAR        = false
        ENABLE_FEDERATED_AVATAR = false

        [attachment]
        PATH = /home/git/data/gitea/attachments

        [log]
        ROOT_PATH = /home/git/data/gitea/log
        MODE      = file
        LEVEL     = Info

        [mailer]
        ENABLED = false

        [service]
        REGISTER_EMAIL_CONFIRM     = false
        ENABLE_NOTIFY_MAIL         = false
        DISABLE_REGISTRATION       = false
        ENABLE_CAPTCHA             = false
        REQUIRE_SIGNIN_VIEW        = false
        DEFAULT_KEEP_EMAIL_PRIVATE = false
        NO_REPLY_ADDRESS           = noreply.example.org

  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: 'gitea-${INSTANCE_IDENTIFIER}'
      labels:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
        gitea: '${GITEA_VERSION}'
        configuration: '${CONFIGURATION_VERSION}'
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
  - apiVersion: v1
    kind: Route
    metadata:
      name: 'gitea-${INSTANCE_IDENTIFIER}'
      labels:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
        gitea: '${GITEA_VERSION}'
        configuration: '${CONFIGURATION_VERSION}'
    spec:
      port:
        targetPort: 'https'
      tls:
        termination: 'passthrough'
      to:
        kind: Service
        name: 'gitea-${INSTANCE_IDENTIFIER}'
  - apiVersion: v1
    kind: Service
    metadata:
      name: 'gitea-${INSTANCE_IDENTIFIER}'
      labels:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
        gitea: '${GITEA_VERSION}'
        configuration: '${CONFIGURATION_VERSION}'
      annotations:
        service.alpha.openshift.io/serving-cert-secret-name: 'gitea-certs-${INSTANCE_IDENTIFIER}'
    spec:
      type: ClusterIP
      ports:
        - name: 'https'
          port: 443
          targetPort: 8443
      selector:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
  - apiVersion: v1
    kind: Route
    metadata:
      name: 'configuration-${INSTANCE_IDENTIFIER}'
      labels:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
        gitea: '${GITEA_VERSION}'
        configuration: '${CONFIGURATION_VERSION}'
    spec:
      port:
        targetPort: 'https'
      tls:
        termination: 'passthrough'
      to:
        kind: Service
        name: 'configuration-${INSTANCE_IDENTIFIER}'
  - apiVersion: v1
    kind: Service
    metadata:
      name: 'configuration-${INSTANCE_IDENTIFIER}'
      labels:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
        gitea: '${GITEA_VERSION}'
        configuration: '${CONFIGURATION_VERSION}'
      annotations:
        service.alpha.openshift.io/serving-cert-secret-name: 'configuration-certs-${INSTANCE_IDENTIFIER}'
    spec:
      type: ClusterIP
      ports:
        - name: 'https'
          port: 443
          targetPort: 8105
      selector:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
  - apiVersion: v1
    kind: DeploymentConfig
    metadata:
      name: 'gitea-${INSTANCE_IDENTIFIER}'
      labels:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
        gitea: '${GITEA_VERSION}'
        configuration: '${CONFIGURATION_VERSION}'
    spec:
      selector:
        app: 'configuration-${INSTANCE_IDENTIFIER}'
      replicas: 1
      template:
        metadata:
          labels:
            app: 'configuration-${INSTANCE_IDENTIFIER}'
            gitea: '${GITEA_VERSION}'
        spec:
          initContainers:
            - name: pem-to-keystore
              image: nginx
              env:
                - name: keyfile
                  value: /var/run/secrets/openshift.io/services_serving_certs/tls.key
                - name: crtfile
                  value: /var/run/secrets/openshift.io/services_serving_certs/tls.crt
                - name: keystore_pkcs12
                  value: /var/run/secrets/java.io/keystores/keystore.pkcs12
                - name: password
                  value: '${STORE_PASSWORD}'
              command: ['sh']
              args: ['-c', "openssl pkcs12 -export -inkey $keyfile -in $crtfile -out $keystore_pkcs12 -password pass:$password -name 'server certificate'"]
              volumeMounts:
                - mountPath: /var/run/secrets/java.io/keystores
                  name: 'configuration-keystore-${INSTANCE_IDENTIFIER}'
                - mountPath: /var/run/secrets/openshift.io/services_serving_certs
                  name: 'configuration-certs-${INSTANCE_IDENTIFIER}'
            - name: pem-to-truststore
              image: openjdk:alpine
              env:
                - name: ca_bundle
                  value: /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
                - name: truststore_jks
                  value: /var/run/secrets/java.io/keystores/truststore.jks
                - name: password
                  value: '${STORE_PASSWORD}'
              command: ['/bin/sh']
              args: ["-c",
                     "keytool -noprompt -importkeystore -srckeystore $JAVA_HOME/jre/lib/security/cacerts -srcstoretype JKS -destkeystore $truststore_jks -storepass $password -srcstorepass changeit && cd /var/run/secrets/java.io/keystores/ && awk '/-----BEGIN CERTIFICATE-----/{filename=\"crt-\"NR}; {print >filename}' $ca_bundle && for file in crt-*; do keytool -import -noprompt -keystore $truststore_jks -file $file -storepass $password -alias service-$file; done && rm crt-*"]
              volumeMounts:
                - mountPath: /var/run/secrets/java.io/keystores
                  name: 'configuration-keystore-${INSTANCE_IDENTIFIER}'
          containers:
            - name: 'gitea-${INSTANCE_IDENTIFIER}'
              image: '...'
              command: ['sh',
                        '-c',
                        'tar xf /app/gitea/gitea-data.tar.gz -C /home/git/data && cp /app/config/local-docker.ini /home/git/config/local-docker.ini && gitea web --config /home/git/config/local-docker.ini']
              ports:
                - containerPort: 8443
                  protocol: TCP
              imagePullPolicy: Always
              volumeMounts:
                - mountPath: '/home/git/data'
                  name: 'gitea-data-${INSTANCE_IDENTIFIER}'
                  readOnly: false
                - mountPath: '/app/config'
                  name: 'gitea-config-${INSTANCE_IDENTIFIER}'
                  readOnly: false
                - mountPath: '/var/run/secrets/service-cert'
                  name: 'gitea-certs-${INSTANCE_IDENTIFIER}'
            - name: 'configuration-${INSTANCE_IDENTIFIER}'
              image: '...'
              env:
                - name: POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
                - name: POD_NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
              command: [
                "java",
                "-Djava.security.egd=file:/dev/./urandom",
                "-Dspring.profiles.active=terraform",
                "-Djavax.net.ssl.trustStore=/var/run/secrets/java.io/keystores/truststore.jks",
                "-Djavax.net.ssl.trustStoreType=JKS",
                "-Djavax.net.ssl.trustStorePassword=${STORE_PASSWORD}",
                "-Dserver.ssl.key-store=/var/run/secrets/java.io/keystores/keystore.pkcs12",
                "-Dserver.ssl.key-store-password=${STORE_PASSWORD}",
                "-Dserver.ssl.key-store-type=PKCS12",
                "-Dserver.ssl.trust-store=/var/run/secrets/java.io/keystores/truststore.jks",
                "-Dserver.ssl.trust-store-password=${STORE_PASSWORD}",
                "-Dserver.ssl.trust-store-type=JKS",
                "-Dspring.cloud.config.server.git.uri=https://gitea-${INSTANCE_IDENTIFIER}.svc.cluster.local/org/centralrepo.git",
                "-jar",
                "/app.jar"
              ]
              ports:
                - containerPort: 8105
                  protocol: TCP
              imagePullPolicy: Always
              volumeMounts:
                - mountPath: '/var/run/secrets/java.io/keystores'
                  name: 'configuration-keystore-${INSTANCE_IDENTIFIER}'
                  readOnly: true
                - mountPath: 'target/centralrepo'
                  name: 'configuration-${INSTANCE_IDENTIFIER}'
                  readOnly: false
          volumes:
            - name: 'gitea-data-${INSTANCE_IDENTIFIER}'
              persistentVolumeClaim:
                claimName: 'gitea-${INSTANCE_IDENTIFIER}'
            - name: 'gitea-config-${INSTANCE_IDENTIFIER}'
              configMap:
                defaultMode: 0660
                name: 'gitea-config-${INSTANCE_IDENTIFIER}'
            - name: 'gitea-certs-${INSTANCE_IDENTIFIER}'
              secret:
                defaultMode: 0640
                secretName: 'gitea-certs-${INSTANCE_IDENTIFIER}'
            - name: 'configuration-keystore-${INSTANCE_IDENTIFIER}'
              emptyDir:
            - name: 'configuration-certs-${INSTANCE_IDENTIFIER}'
              secret:
                defaultMode: 0640
                secretName: 'configuration-certs-${INSTANCE_IDENTIFIER}'
            - name: 'configuration-${INSTANCE_IDENTIFIER}'
              emptyDir:
                defaultMode: 660
          restartPolicy: Always
          terminationGracePeriodSeconds: 62
          dnsPolicy: ClusterFirst
    strategy:
      type: RollingUpdate
      rollingUpdate:
        maxUnavailable: 1
        maxSurge: 1
parameters:
  - name: GITEA_VERSION
    displayName: Gitea Image Version
    description: The version of the gitea image.
    required: true
  - name: CONFIGURATION_VERSION
    displayName: Configuration Service Image Version
    description: The version of the configuration service image.
    required: true
  - name: INSTANCE_IDENTIFIER
    description: Provides an identifier to tie all objects in the deployment together.
    generate: expression
    from: "[a-z0-9]{6}"
  - name: STORE_PASSWORD
    generate: expression
    from: "[a-zA-Z0-9]{25}"
4

0 回答 0