首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kubernetes部署可以从OpenShift模板文件完成吗?

Kubernetes部署可以从OpenShift模板文件完成吗?
EN

Stack Overflow用户
提问于 2021-06-26 04:19:11
回答 2查看 129关注 0票数 0

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

由于这方面的信息有限,我只是试图将其转换为看看会发生什么,但我无法使其工作。如果有人能阐明这个主题,以及在哪里可以找到如何从DeploymentConfigs到部署的好例子,我想互联网和我都会很感激。

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

代码语言:javascript
复制
...
- 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
...
EN

回答 2

Stack Overflow用户

发布于 2021-06-26 15:29:56

根据官方OpenShift documentation的说法,你没有理由不能进行模板部署。

但是,deploymentConfigs和部署是不同的。因此,简单地更改apiVersion和kind来匹配部署可能会导致OpenShift无法理解的yaml。

例如,您提供的DeploymentConfig包含一个“triggers”部分。触发器可用于DeploymentConfigs,但不可用于部署。

顺便说一句: openshift模板仍然是一种东西,但是你应该考虑使用一个不同的更广泛的模板工具,比如helm v3。它更常用,可以应用于OpenShift和普通Kubernetes集群(假设在舵表中只有普通kubernetes资源类型/crd)。

票数 0
EN

Stack Overflow用户

发布于 2021-06-30 02:15:53

答案是肯定的,但现在你必须为triggers和git钩子等东西拿出自己的解决方案。对我来说,上述DeploymentConfig的转换结果如下所示:

代码语言:javascript
复制
...
- 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
...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68136662

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档