I am using OpenShift 4.7 and I want to convert my OpenShift DeploymentConfigs to Kubernetes Deployments. Right now, I'm creating most of my applications with an OpenShift kind: Template
file. Do OpenShift Templates support Kubernetes Deployments or do I need to switch to another kind of tool if I want to use Kubernetes Deployments?
Because of the limited information around this, I just tried to convert it to see what would happen and I couldn't get it to work. If someone could shed light on this subject and where to find good examples of how to go from DeploymentConfigs to Deployments I think the internet and I would appreciate that.
One of my current OpenShift DeploymentConfigs looks like this within a Template file:
...
- 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
...
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).