0

我正在使用 OpenShift 4.7,我想将我的 OpenShift DeploymentConfigs 转换为 Kubernetes Deployments。现在,我正在使用 OpenShiftkind: Template文件创建大部分应用程序。OpenShift 模板是否支持 Kubernetes 部署,或者如果我想使用 Kubernetes 部署,我是否需要切换到另一种工具?

由于这方面的信息有限,我只是尝试对其进行转换以查看会发生什么,但无法使其正常工作。如果有人可以阐明这个主题以及在哪里可以找到如何从 DeploymentConfigs 到 Deployments 的好例子,我认为互联网和我会很感激。

我当前的 OpenShift DeploymentConfig 之一在模板文件中如下所示:

...
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    annotations:
      description: Defines how to deploy the database
      template.alpha.openshift.io/wait-for-ready: 'true'
    name: postgresql
  spec:
    replicas: 1
    selector:
      name: postgresql
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          name: postgresql
        name: postgresql
      spec:
        containers:
        - env:
          - name: POSTGRESQL_USER
            valueFrom:
              secretKeyRef:
                key: database-user
                name: ${NAME}
          - name: POSTGRESQL_PASSWORD
            valueFrom:
              secretKeyRef:
                key: database-password
                name: ${NAME}
          - name: POSTGRESQL_DATABASE
            value: ${DATABASE_NAME}
          image: ' '
          livenessProbe:
            exec:
              command:
              - /usr/libexec/check-container
              - --live
            initialDelaySeconds: 120
            timeoutSeconds: 10
          name: postgresql
          ports:
          - containerPort: 5432
          readinessProbe:
            exec:
              command:
              - /usr/libexec/check-container
            initialDelaySeconds: 5
            timeoutSeconds: 1
          resources:
            limits:
              memory: ${MEMORY_POSTGRESQL_LIMIT}
          volumeMounts:
          - mountPath: /var/lib/pgsql/data
            name: postgresql-data
        volumes:
        - name: postgresql-data
          persistentVolumeClaim:
            claimName: postgresql
    triggers:
    - imageChangeParams:
        automatic: true
        containerNames:
        - postgresql
        from:
          kind: ImageStreamTag
          name: postgresql:${POSTGRESQL_VERSION}
          namespace: ${NAMESPACE}
      type: ImageChange
    - type: ConfigChange
...
4

2 回答 2

0

according to the official OpenShift documentation there is no reason why you shouldn't be able to template deployments.

However, deploymentConfigs and Deployments are not the same. So simply changing the apiVersion and kind to match deployments might lead to yaml that is not understandable by OpenShift.

For example the DeploymentConfig you provided contains a 'triggers' section. Triggers are available for DeploymentConfigs but not for Deployments.

On a side note: openshift templates are still a thing, however you should thinkg about using a different more widespread templating tool like helm v3. It is more commonly used, can be applied to OpenShift and plain Kubernetes clusters (assuming there are only plain kubernetes ressource types/crd's in that helm chart).

于 2021-06-26T07:29:56.013 回答
0

答案是肯定的,但你现在必须想出自己的解决方案来解决triggersgit hooks 之类的问题。上述 DeploymentConfig 的转换对我来说如下所示:

...
- apiVersion: v1
  kind: Deployment
  metadata:
    annotations:
      deployment.kubernetes.io/revision: '4'
      image.openshift.io/triggers: |-
        [
          {
            "from": {
              "kind": "ImageStreamTag",
              "namespace": "openshift",
              "name": "openshift/postgresql:10"
            },
            "fieldPath": "spec.template.spec.containers[0].image"
          }
        ]
    selfLink: /apis/apps/v1/namespaces/abigail-discourse-project-1/deployments/postgresql
    name: postgresql
    #namespace: ${openshift.project()}
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: postgresql
    template:
      metadata:
        creationTimestamp: null
        labels:
          app: postgresql
      spec:
        containers:
          - resources: {}
            readinessProbe:
              exec:
                command:
                  - /usr/libexec/check-container
              initialDelaySeconds: 5
              timeoutSeconds: 1
              periodSeconds: 9
              successThreshold: 1
              failureThreshold: 3
            terminationMessagePath: /dev/termination-log
            name: postgresql
            livenessProbe:
              exec:
                command:
                  - /usr/libexec/check-container --live
              initialDelaySeconds: 120
              timeoutSeconds: 1
              periodSeconds: 15
              successThreshold: 1
              failureThreshold: 3
            env:
              - name: POSTGRESQL_DATABASE
                value: discourse
              - name: POSTGRESQL_USER
                valueFrom:
                  secretKeyRef:
                    name: discourse
                    key: database-user
              - name: POSTGRESQL_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: discourse
                    key: database-password
            ports:
              - containerPort: 5432
                protocol: TCP
            imagePullPolicy: Always
            envFrom:
              - secretRef:
                  name: discourse
            image: >-
              image-registry.openshift-image-registry.svc:5000/openshift/postgresql:10
        restartPolicy: Always
    strategy:
      type: Recreate
...
于 2021-06-29T18:15:53.317 回答