Reputation: 1
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
...
Upvotes: 0
Views: 1344
Reputation: 1
The answer is yes but you will have to come up with your own solution for things like triggers
and git hooks for now. The conversion from the above DeploymentConfig looked like the following for me:
...
- 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
...
Upvotes: 0
Reputation: 1948
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).
Upvotes: 0