Templates and Operators
Let’s talk about OpenShift 4.12 templates and operators, both powerful ways to create and deploy applications on OpenShift.
Templates
OpenShift templates are YAML or JSON files that describe the desired state of application components, such as pods, services, routes, and build configurations. You can use templates to define reusable and parameterized application configurations that can be instantiated with a single command or through the web console.
Templates can help you simplify and automate the creation of complex applications, such as microservices, that consist of multiple components that need to communicate with each other. You can also use templates to share best practices and common patterns for deploying applications on OpenShift.
apiVersion: template.openshift.io/v1
kind: Template (1)
metadata:
name: postgresql
parameters:
- name: APPLICATION_NAME (2)
description: "The application name"
value: postgresql
- name: POSTGRESQL_USER
description: "Username of the PostgreSQL user"
value: user
objects:
- apiVersion: v1
kind: DeploymentConfig
metadata:
labels:
app: ${APPLICATION_NAME} (3)
name: ${APPLICATION_NAME}
spec:
replicas: 1
selector:
app: ${APPLICATION_NAME}
strategy:
1 | Definition of a template conforming to the OpenShift CRD. |
2 | Declaration of an APPLICATION_NAME parameter. |
3 | Usage of the APPLICATION_NAME parameter. |
You can see the full contents of a template in action in the 04_02 branch of the GitHub repository for this course, in the file 00-postgresql-template.yaml .
|
OpenShift 4.12 introduces some new features and enhancements for templates:
-
Support for Helm charts, which are a popular way to package and distribute Kubernetes applications. You can now use Helm charts as templates on OpenShift and leverage the Helm CLI and the OpenShift web console to install and manage them.
-
Improved template editing and validation in the web console, which makes it easier to create and modify templates with a graphical interface and provides instant feedback on syntax errors and parameter values.
-
New template samples and quick starts, which provide ready-to-use examples of common application scenarios, such as deploying a Node.js application or a PostgreSQL database. You can access these samples and quick starts from the Developer Catalog or the Add page in the web console.
Operators
Operators are a powerful way to automate the deployment and management of Kubernetes-native applications on OpenShift. Operators are software extensions that act like a vendor’s engineering team, monitoring the cluster state and making decisions in real time. Operators can provide automation at every level of the stack, from the platform components to the applications that run on top of it.
Operators are packaged, deployed, and managed through OperatorHub, a registry of certified operators from software vendors and open-source projects. Users can browse and install operators from the OperatorHub with a few clicks, and get updates and patches automatically. Operators can also expose configuration options through custom resource definitions (CRDs), allowing users to fine-tune their applications according to their needs.
OpenShift operators make it easier to run complex and stateful applications on Kubernetes, such as databases, message queues, or monitoring systems. Operators can handle tasks such as provisioning, scaling, backup, recovery, and upgrade, reducing the operational burden on users. Operators can also integrate with other OpenShift features, such as security, networking, and logging, to provide a consistent and seamless user experience.
To see operators in action, check the following chapters: Serverless with Knative, Logging, and Using CI/CD Pipelines. |