Professional Documents
Culture Documents
Workshop
Red Hat OpenShift
Yohanes
MW Consultant
Application Migration and
Modernization
What is Application Migration?
Definition
Different vendor
and / or AS - IS Migration TO - BE
major version
Infrastructure
hardware + virtualization + OS +JVM + application container
Knowledge
Migrate in
Explore Analyze Prove Plan
Iterations
Analyze
A
C
B
D E F
A
C
B
D E F
Red Hat
Consulting
and/or Partner’s Partner and/or
Migration Knowledge Customer
specialists Migration
and/or Customer’s Specialists / base Teams
specialists Center of (wiki and migration
rules) (1…N)
Excellence
Challenge
Backlog
Regression testing
6 Sign off to deploy 5 Functional testing 4 Build and deploy application
application Non-functional testing
Performance testing
Stress testing
Manual testing
Regression testing
6 Sign off to deploy 5 Functional testing 4 Build and deploy application
application Non-functional testing
writing code.
1 Request a VM 2 Request a middleware 3 Set up the environment for
Regression testing
6 Sign off to deploy 5 Functional testing 4 Build and deploy application
application Non-functional testing
Performance testing
Stress testing
Manual testing
Regression testing
6 Sign off to deploy 5 Functional testing 4 Build and deploy application
application Non-functional testing
Performance testing
Stress testing
Manual testing
Doing more
with less
Agile DevOps
30 DEVOPS MATURITY ASSESSMENT Based on Mike Rother's Improvement Kata, highlighted in Lean Enterprise (Humble et al.,
2015)
DevOps/Continuous Delivery
Improvement Model
People
Process Technology
People
Culture and
Release
Organization
People
Culture and
Release
Organization
People
Culture and
Release
Organization
Derived from Continuous Delivery Maturity Models from InfoQ, UrbanCode, ThoughtWorks,
35 DEVOPS MATURITY ASSESSMENT Bekk, and others.
Culture and Organization
Pathological (power-oriented) Bureaucratic (rule-oriented) Generative
(performance-oriented)
People
Culture and
Release
Organization
Separate test environment. Code analysis. Full automatic integration Manual exploratory testing. Defects found and fixed
tests. immediately (roll forward).
Test coverage analysis. Automatic performance
Behavior-driven tests.
development.
Automatic security tests.
Derived from Continuous Delivery Maturity Models from InfoQ, UrbanCode, ThoughtWorks,
38 DEVOPS MATURITY ASSESSMENT Bekk, and others.
Test and Verification
People
Culture and
Release
Organization
Derived from Continuous Delivery Maturity Models from InfoQ, UrbanCode, ThoughtWorks,
41 DEVOPS MATURITY ASSESSMENT Bekk, and others.
DevOps/Continuous Delivery
Improvement Model
Information Build and
and Reporting Deploy
People
Culture and
Release
Organization
Derived from Continuous Delivery Maturity Models from InfoQ, UrbanCode, ThoughtWorks,
43 DEVOPS MATURITY ASSESSMENT Bekk, and others.
Build and Deploy
Continuous Integration
DEFINITION:
Every time somebody commits a change, the entire application is built and a comprehensive
set of automated tests are run against it. (Humble and Farley, 2011)
● Requires frequent code check ins, good test coverage, preferably a CI server
BENEFITS:
● Normal state of the application is working, functional
● If the application is broken, it is treated as abnormal and requiring immediate attention
TOOLS:
● Version control, CI server
People
Culture and
Release
Organization
Derived from Continuous Delivery Maturity Models from InfoQ, UrbanCode, ThoughtWorks,
46 DEVOPS MATURITY ASSESSMENT Bekk, and others.
DevOps/Continuous Delivery
Improvement Model
Information Build and
and Reporting Deploy
People
Culture and
Release
Organization
Derived from Continuous Delivery Maturity Models from InfoQ, UrbanCode, ThoughtWorks,
48 DEVOPS MATURITY ASSESSMENT Bekk, and others.
LINUX CONTAINERS
WHAT ARE CONTAINERS?
It Depends Who You Ask
INFRASTRUCTURE APPLICATIONS
Hypervisor
Hardware
Hardware
Application Application
OS dependencies OS dependencies
Operating System
Container Host
Application Application
Clear ownership boundary Dev
IT Ops OS dependencies between Dev and IT Ops OS dependencies
(and Dev, sort of)
drives DevOps adoption
Operating System and fosters agility Container Host
IT Ops
Infrastructure Infrastructure
Image Layer 3
Application Layer
CONTAINER
CONTAINER
CONTAINER
IMAGE
BINARY RUNTIME
IMAGE REGISTRY
CONTAINER
IMAGE REGISTRY
myregistry/frontend myregistry/mongo
frontend:latest mongo:latest
frontend:2.0 mongo:3.7
frontend:1.1 CONTAINER mongo:3.6 CONTAINER
frontend:1.0 IMAGE
mongo:3.4 IMAGE
POD POD
DEPLOYMENT
BACKEND SERVICE
role: backend
Invoke
Backend API
BACKEND SERVICE
role: backend
ROUTE
app-prod.mycompany.com
> curl http://app-prod.mycompany.com
BACKEND SERVICE
Container
C Cc
Image
C C C
C C C C
Pod C
C C
c
C C C
C C C C
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
API/AUTHENTICATION
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
API/AUTHENTICATION
DATA STORE
RHEL RHEL RHEL
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
PHYSICAL
PHYSICAL
VIRTUALVIRTUAL
PRIVATEPRIVATEPUBLIC PUBLICHYBRID HYBRID
API/AUTHENTICATION
DATA STORE
RHEL RHEL RHEL
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
API/AUTHENTICATION
DATA STORE
RHEL RHEL RHEL
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
C C
DATA STORE
RHEL RHEL RHEL
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
C C
DATA STORE
RHEL RHEL RHEL
HEALTH/SCALING
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
SERVICE LAYER
C C C
DATA STORE
RHEL RHEL RHEL
HEALTH/SCALING C C C C
C
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
SERVICE LAYER
C C C
DATA STORE
RHEL RHEL RHEL
HEALTH/SCALING C C C C
C
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
SERVICE LAYER
C C C
DATA STORE
RHEL RHEL RHEL
HEALTH/SCALING C C C C
C
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
SERVICE LAYER
C C C
CI/CD DATA STORE
RHEL RHEL RHEL
EXISTING C C C C
HEALTH/SCALING
AUTOMATION
TOOLSETS
C
RED HAT
ENTERPRISE LINUX
RHEL RHEL RHEL
API/AUTHENTICATION
C C C
DATA STORE
RHEL RHEL RHEL
C C
HEALTH/SCALING c
RED HAT
ENTERPRISE LINUX RHEL RHEL RHEL
API/AUTHENTICATION
C C C
DATA STORE
RHEL RHEL RHEL
C C
HEALTH/SCALING c
RED HAT
ENTERPRISE LINUX RHEL RHEL RHEL
API/AUTHENTICATION
C C C
DATA STORE
RHEL RHEL RHEL
C C
HEALTH/SCALING c
RED HAT
ENTERPRISE LINUX RHEL RHEL RHEL
API/AUTHENTICATION
C C C
DATA STORE
RHEL RHEL RHEL
C C
HEALTH/SCALING c
RED HAT
ENTERPRISE LINUX RHEL RHEL RHEL
c c
API/AUTHENTICATION
C C C
DATA STORE
RHEL RHEL RHEL
C C
HEALTH/SCALING
RED HAT
ENTERPRISE LINUX RHEL RHEL
ROUTER
INTERNAL TRAFFIC
SERVICE
Canary Deployments
POD
EGRESS
EXTERNAL
POD EGRESS SERVICE ROUTER SERVICE
INTERNAL-IP:8080
POD
IP1 Whitelist: IP1
NODE
IP1
POD
OPENSHIFT
KUBERNETES CNI
Contrail
OpenShift Essentials Cisco VMware Open
Flannel Nuage (OpenCont Big Switch
Plugin (Calico) Contiv NSX-T Daylight
Plugin* Plugin rail) Plugin
Plugin Plugin Plugin Plugin
DEFAULT Plugin
* Flannel is minimally verified and is supported only and exactly as deployed in the OpenShift on OpenStack reference architecture
NODE NODE
172.16.1.10 172.16.1.20
IP Network
MULTI-TENANT NETWORK
NODE NODE
●
●
Project-level network isolation
Multicast support
POD POD
✓ POD POD
✓ ✓ matchLabels:
color: purple
POD POD ingress:
- ports:
- protocol: tcp
port: 8080
NODE
veth0
POD 1
10.1.15.2/24
br0
vxlan0 eth0
10.1.15.1/24
192.168.0.100
veth1
POD 2
10.1.15.3/24
NODE 2
veth0 br0
POD 2 vxlan0 eth0
10.1.20.2/24 10.1.20.1/24
192.168.0.200
Container
NODE 1 to Container on Different Hosts
POD 1
veth0 br0
tun0 eth0
External
10.1.15.2/24 10.1.15.1/24 Host
192.168.0.100
etcd
NODE 2 flanneld
Flannel is minimally verified and is supported only and exactly as deployed in the OpenShift
on OpenStack reference architecture https://access.redhat.com/articles/2743631
● Access control
○ Cluster administrators can view all logs
○ Users can only view logs for their projects
NODE
ADMIN
NODE
RHEL
POD POD APPLICATION LOGS
POD POD
FLUENTD
ELASTIC ELASTIC
ELASTIC ELASTIC
RHEL ELASTICSEARCH KIBANA
POD POD
USER
RHEL
NODE
RED HAT
POD POD CLOUDFORMS
CONTAINER METRICS
FLUENTD
NODE
POD POD API OPENSHIFT
HEAPSTER HAWKULAR
WEB CONSOLE
POD POD
FLUENTD
NODE
RHEL USER
POD POD CUSTOM
DASHBOARDS
POD POD ELASTIC
CADVISOR
ELASTIC
CASSANDRA
RHEL
POD POD
RHEL
CERTIFICATE CHECKS
● master and nodes
● etcd certificates
OpenStack
NFS iSCSI Azure Disk AWS EBS FlexVolume
Cinder
register PV Ceph
iSCSI GlusterFS NFSP NFSP NFSP
RBD
PV PV V V V
PV
Admin
create claim
Slow Azure
Azure-Disk Provisioner
provision
Admin Fastest NetApp
PV
NetApp-Flash Provisioner
Pod
(OpenShift)
Developer
Source-to-Image
BUILD IMAGE (S2I)
DEPLOY Application
Container
deploy
(OpenShift)
Source-to-Image
BUILD IMAGE (S2I)
DEPLOY Application
Container
deploy
(OpenShift)
Image
PUSH Registry
(Build Infra)
DEPLOY Application
Container
deploy
(Openshift)
BUILD STAGE 1
BUILD STAGE 3
BUILD STAGE 2
Use Source-to-Image to build app binaries and deploy on lean vanilla runtimes
Use your choice of build tool like Gradle and deploy to official images like the JDK image
Custom
Scratch
Go S2I
Image
Builder Image
BUILDS
● Webhook triggers: build the app image whenever the code changes
● Image trigger: build the app image whenever the base language or app runtime changes
● Build hooks: test the app image before pushing it to an image registry
DEPLOYMENTS
● Deployment triggers: redeploy app containers whenever configuration changes or the
image changes in the OpenShift integrated registry or upstream registries
physical
virtual
private cloud
dev source CI/CD container
repository engine
public cloud
OPENSHIFT
EXISTING
S2I
run job CI/CD INFRA build Build
APP APP
APPLICATION
IMAGE
OPENSHIFT
CI/CD PIPELINE
(JENKINS)
IMAGE BUILD
& DEPLOY
OPENSHIFT OPENSHIFT
IMAGE IMAGE
REGISTRY REGISTRY
OPENSHIFT OPENSHIFT
CLUSTER CLUSTER
OPENSHIFT
CI/CD PIPELINE
(JENKINS)
IMAGE BUILD PROMOTE
& DEPLOY TO TEST
OPENSHIFT OPENSHIFT
IMAGE IMAGE
REGISTRY REGISTRY
OPENSHIFT OPENSHIFT
CLUSTER CLUSTER
OPENSHIFT
CI/CD PIPELINE
(JENKINS)
IMAGE BUILD PROMOTE PROMOTE
& DEPLOY TO TEST TO UAT
OPENSHIFT OPENSHIFT
IMAGE IMAGE
REGISTRY REGISTRY
OPENSHIFT OPENSHIFT
CLUSTER CLUSTER
☒
OPENSHIFT
CI/CD PIPELINE
(JENKINS)
☑
IMAGE BUILD PROMOTE PROMOTE
& DEPLOY TO TEST TO UAT
OPENSHIFT OPENSHIFT
IMAGE IMAGE
REGISTRY REGISTRY
OPENSHIFT OPENSHIFT
CLUSTER CLUSTER
GO
LIVE?
☒
OPENSHIFT
☑
CI/CD PIPELINE
(JENKINS)
IMAGE BUILD PROMOTE PROMOTE PROMOTE
& DEPLOY TO TEST TO UAT TO PROD
DEVELOPER
OPENSHIFT OPENSHIFT
IMAGE IMAGE
REGISTRY REGISTRY
OPENSHIFT OPENSHIFT
CLUSTER CLUSTER
BUILD APP RUN PROMOTE APP BUILD CONTAINER RUN PROMOTE CONTAINER
BINARY TESTS BINARY IMAGE TESTS IMAGE
SOURCE
VERSION
CONTROL
ENTERPRISE ENTERPRISE
BINARY REPO IMAGE REGISTRY
BUILD APP RUN PROMOTE APP BUILD CONTAINER RUN PROMOTE CONTAINER
BINARY TESTS BINARY IMAGE TESTS IMAGE
SOURCE
VERSION
CONTROL
ENTERPRISE ENTERPRISE
BINARY REPO IMAGE REGISTRY
AWS ECR
EXISTING
DELIVERY
PROCESS
OPENSHIFT
CLUSTER
ENTERPRISE
IMAGE
REGISTRY
OPENSHIFT OPENSHIFT
IMAGE IMAGE
REGISTRY REGISTRY
OPENSHIFT OPENSHIFT
CLUSTER CLUSTER
VIRTUAL VIRTUAL
MACHINE MACHINE
Local
Bootstrap Develop Verify Git Push Pipeline
Deploy
Local
Bootstrap Develop Verify Git Push Pipeline
Deploy
BOOTSTRAP
● Pick your programming language and application runtime of choice
● Create the project skeleton from scratch or use a generator such as
○ Maven archetypes
○ Quickstarts and Templates
○ OpenShift Generator
○ Spring Initializr
Local
Bootstrap Develop Verify Git Push Pipeline
Deploy
DEVELOP
● Pick your framework of choice such as Java EE, Spring, Ruby on Rails, Django, Express, ...
● Develop your application code using your editor or IDE of choice
● Build and test your application code locally using your build tools
● Create or generate OpenShift templates or Kubernetes objects
Local
Bootstrap Develop Verify Git Push Pipeline
Deploy
LOCAL DEPLOY
● Deploy your code on a local OpenShift cluster
○ Red Hat Container Development Kit (CDK), minishift and oc cluster
● Red Hat CDK provides a standard RHEL-based development environment
● Use binary deploy, maven or CLI rsync to push code or app binary directly into
containers
Local
Bootstrap Develop Verify Git Push Pipeline
Deploy
VERIFY
● Verify your code is working as expected
● Run any type of tests that are required with or without other components (database, etc)
● Based on the test results, change code, deploy, verify and repeat
Local
Bootstrap Develop Verify Git Push Pipeline
Deploy
GIT PUSH
● Push the code and configuration to the Git repository
● If using Fork & Pull Request workflow, create a Pull Request
● If using code review workflow, participate in code review discussions
Local
Bootstrap Develop Verify Git Push Pipeline
Deploy
PIPELINE
● Pushing code to the Git repository triggers one or multiple deployment pipelines
● Design your pipelines based on your development workflow e.g. test the pull request
● Failure in the pipeline? Go back to the code and start again
Real Time
Integration Messaging Data Grid
Decision
Spring Cloud
Eclipse Vert.x WildFly Swarm Node.js Spring Boot
(partial)
OPENSHIFT
OPENSHIFT
ROLLING STRATEGY
All rolling deployments in OpenShift Container Platform are canary deployments; a new
version (the canary) is tested before all of the old instances are replaced. When to Use a
Rolling Deployment:
● When you want to take no downtime during an application update.
● When your application supports having old code and new code running at the same time.
OPENSHIFT
BLUE GREEN STRATEGY
Use a blue-green deployment when you want to test a new version of your application in a
production environment before moving traffic to it.
Blue-green deployments make switching between two different versions of your application
easy. However, since many applications depend on persistent data, you will need to have an
application that supports N-1 compatibility if you share a database, or implement a live data
migration between your database, store, or disk if you choose to create two copies of your
data layer.
OPENSHIFT
A/B STRATEGY
OPENSHIFT
APPLICATION CONFIGURATION
- apiVersion: v1 - apiVersion: v1
kind: ConfigMap kind: DeploymentConfig
metadata: ...
name: app-config spec:
data: template:
product.per.page: 10 spec:
thumbnail.size: medium containers:
ui.properties: |- volumeMounts:
header.bg.color=red - name: config-volume
header.fg.color=white mountPath: /etc/config
... volumes:
- name: config-volume
configMap:
name: app-config
...
OPENSHIFT
TEMPLATES
TEMPLATES
● Describes set of resources that an application is composed of
○ Pods
○ BuildConfigs
○ DeploymentConfigs
○ etc
● Simplifies deploying multi-component applications e.g. create instantly deployable applications for developers or
customers
● Can be parameterized
○ Application name, datasource, passwords, etc
● Some provided by OpenShift.
● Users are encouraged to create their own
OPENSHIFT
TEMPLATES
OPENSHIFT
TEMPLATES
apiVersion: v1
kind: Template
labels:
template: eap64-basic-s2i
xpaas: 1.2.0
metadata:
annotations:
description: Application template for EAP 6 applications built using S2I.
iconClass: icon-jboss
tags: eap,javaee,java,jboss,xpaas
version: 1.2.0
Template name name: eap64-basic-s2i
namespace: openshift
Parameters parameters:
to set when - description: The name for the application.
instantiated name: APPLICATION_NAME
required: true
value: eap-app
List of objects in this ...
template
objects:
...
OPENSHIFT
TEMPLATES
● Describes set of resources that an application is composed of
○ Pods
○ BuildConfigs
○ DeploymentConfigs
○ etc
● Simplifies deploying multi-component applications e.g. create instantly deployable
applications for developers or customers
● Can be parameterized
○ Application name, datasource, passwords, etc
● Some provided by OpenShift.
● Users are encouraged to create their own
OPENSHIFT
TEMPLATES
OPENSHIFT
TEMPLATES
apiVersion: v1
kind: Template
labels:
template: eap64-basic-s2i
xpaas: 1.2.0
metadata:
annotations:
description: Application template for EAP 6 applications built using S2I.
iconClass: icon-jboss
tags: eap,javaee,java,jboss,xpaas
version: 1.2.0
Template name name: eap64-basic-s2i
namespace: openshift
Parameters parameters:
to set when - description: The name for the application.
instantiated name: APPLICATION_NAME
required: true
value: eap-app
...
OPENSHIFT
Creating App From Template
OPENSHIFT
CREATING APP FROM TEMPLATE
● Default templates in OpenShift are installed in the openshift namespace. Examine the
list of installed templates
● Review the defined parameters and how they are referenced throughout the template
OPENSHIFT
CREATING APP FROM TEMPLATE
● Create a new application based on the cakephp-mysql-example template
$ oc new-project lab6
$ oc new-app cakephp-mysql-example
Parameter values can be specified through the -p option. Otherwise default values will
be used as defined in the template
OPENSHIFT
CREATING APP FROM TEMPLATE
● Examine the default, specified and generated parameter values used for creating the app
--> Deploying template cakephp-mysql-example in project openshift for "cakephp-mysql-example"
With parameters:
Memory Limit=512Mi
Memory Limit (MySQL)=512Mi
Git Repository URL=https://github.com/openshift/cakephp-ex.git
Git Reference=
Context Directory=
Application Hostname=
GitHub Webhook Secret=in8i20Rpx65o2sOQofNxP7qYXFKWeUn2lyjPUWvf # generated
Database Service Name=mysql
Database Engine=mysql
Database Name=default
Database User=cakephp
Database Password=0JCtLW8st4VVibwu # generated
CakePHP secret token=HX80JvCJyVR1CybPqiYsCEmEOGlySMXzg9Dyn396u8ewRZfvga # generated
CakePHP Security Salt=n8ss4YPtNCJoevCnTqm2niJpddOg6rpkMkywCMDq # generated
CakePHP Security Cipher Seed=245017463845348753867547461804 # generated
OPcache Revalidation Frequency=2
--> Creating resources with label app=cakephp-mysql-example ...
...
--> Success
OPENSHIFT
CREATING APP FROM TEMPLATE
● Verify the application is
deployed by pointing the
browser to the route url
OPENSHIFT
Creating Templates
OPENSHIFT
CREATING TEMPLATES
● Multiple approaches
○ Modify an example template in YAML/JSON
○ Create objects individually, export as template and add parameters
● In this lab, you will create a database and two components and convert that to a template
● Create a new project
$ oc new-project lab7
$ oc new-app --labels=app=lab7
--file=https://raw.githubusercontent.com/openshift/origin/master/examples/db-templates/postgresql-ephemeral-templat
e.json
OPENSHIFT
CREATING TEMPLATES
● Take note of the database name and generated username and password
OPENSHIFT
CREATING TEMPLATES
● Verify PostgreSQL container is running
$ oc get pods
NAME READY STATUS RESTARTS AGE
postgresql-1-h7nz4 1/1 Running 0 8m
● Create a NodeJS application as backend. Set the database info recorded in previous
steps as environment variables for the backend component
$ oc new-app https://github.com/openshift/nodejs-ex.git --name=backend --labels=app=lab7 \
-e POSTGRESQL_USER=userF6V,POSTGRESQL_PASSWORD=JN7lF7KtIVTp5xxn,POSTGRESQL_DB_NAME=sampledb
● Verify the build has been successful and the application is running
$ oc get pods
NAME READY STATUS RESTARTS AGE
backend-1-build 0/1 Completed 0 2m
backend-1-5ozaa 1/1 Running 0 42s
postgresql-1-h7nz4 1/1 Running 0 17m
OPENSHIFT
CREATING TEMPLATES
● The backend component can find and access the PostgreSQL database through the
environment variables. Verify the env vars set within the backend container
$ oc get pods | grep backend
backend-1-5ozaa 1/1 Running 0 4s
backend-1-build 0/1 Completed 0 1m
PostgreSQL host and port env vars are set by OpenShift to inform containers about
available services within the project.
OPENSHIFT
CREATING TEMPLATES
OPENSHIFT
CREATING TEMPLATES
● Create a PHP application as frontend
● Verify the build has been successful and the application is running
[vagrant@rhel-cdk vagrant_data]$ oc get pods
NAME READY STATUS RESTARTS AGE
backend-1-build 0/1 Completed 0 12m
backend-1-t8e0d 1/1 Running 0 10m
frontend-1-6q1ka 1/1 Running 0 23s
frontend-1-build 0/1 Completed 0 1m
postgresql-1-h7nz4 1/1 Running 0 27m
OPENSHIFT
CREATING TEMPLATES
● Create a route for the frontend service
$ oc expose service frontend --name=app --labels=app=lab7
$ oc get service
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
backend 172.30.214.254 <none> 8080/TCP app=backend,deploymentconfig=backend 44m
frontend 172.30.10.30 <none> 8080/TCP app=frontend,deploymentconfig=frontend 1h
postgresql 172.30.34.200 <none> 5432/TCP name=postgresql 1h
$ oc get route
NAME HOST/PORT PATH SERVICE LABELS INSECURE POLICY TLS TERMINATION
app app-lab7.rhel-cdk.10.1.2.2.xip.io frontend app=lab7
OPENSHIFT
CREATING TEMPLATES
● Export all objects as a template
● Clean up the template (remove image references, change label names, etc)
OPENSHIFT
CREATING TEMPLATES
● Template labels can be defined so that they get applied to every object defined in the
template. Add a template label org=internal
apiVersion: v1
kind: Template
metadata:
creationTimestamp: null
name: lab7-template
labels:
org: internal
objects:
...
OPENSHIFT
CREATING TEMPLATES
● PostgreSQL username and password are hard-coded in the template. Parametrize those
values to be generated when the template is instantiated
apiVersion: v1
kind: Template
metadata:
creationTimestamp: null
name: lab7-template
labels:
org: internal
parameters:
- description: Database user name
from: user[a-zA-Z0-9]{3}
generate: expression generate
name: DB_USERNAME
required: true
value
- description: Database user password
from: '[a-zA-Z0-9]{8}'
generate: expression
name: DB_PASSWORD
required: true
objects:
...
OPENSHIFT
CREATING TEMPLATES
● You also need to modify the PostgreSQL and backend DeploymentConfigs so that
they use the generate parameter values instead of the hard-coded ones
- apiVersion: v1 - apiVersion: v1
kind: DeploymentConfig kind: DeploymentConfig
metadata: metadata:
... ...
name: postgresql name: backend
spec: spec:
template: template:
spec: spec:
containers: containers:
- env: - env:
- name: POSTGRESQL_USER - name: POSTGRESQL_DB_NAME
value: ${DB_USERNAME} value: sampledb
- name: POSTGRESQL_PASSWORD - name: POSTGRESQL_PASSWORD
value: ${DB_PASSWORD} value: ${DB_PASSWORD}
- name: POSTGRESQL_DATABASE - name: POSTGRESQL_USER
value: sampledb value: ${DB_USERNAME}
... ...
OPENSHIFT
CREATING TEMPLATES
● Now you have a template file that can be imported to any OpenShift environment and
recreate the entire application on-demand for example for setting up new test
environments. Create a new project for test:
$ oc new-project lab7-test
OPENSHIFT
CREATING TEMPLATES
● Create a new-application based on the template. Notice the generated values for the
template parameters
$ oc new-app lab7-template
--> Deploying template lab7-template for "lab7-template"
With parameters:
DB_USERNAME=userfPD # generated
DB_PASSWORD=QhfV17ES # generated
In order to specify value for the template parameters instead of generating them, you
can use the -p flag
OPENSHIFT
THANK YOU
plus.google.com/+RedHat facebook.com/redhatinc
linkedin.com/company/red-hat twitter.com/RedHat
youtube.com/user/RedHatVideos