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



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

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

我当前的一个OpenShift DeploymentConfigs在模板文件中是这样的:

...
- 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
...

根据OpenShift的官方文档,没有理由不能对部署进行模板化。

但是,deploymentConfig和Deployments并不相同。因此,简单地更改apiVersion和种类以匹配部署可能会导致OpenShift无法理解的yaml。

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

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

答案是肯定的,但您现在必须为triggers和git hook之类的东西想出自己的解决方案。上面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
...

最新更新