Install multi-container applications by using the Kustomize CLI.
Outcomes
Customize a Red Hat OpenShift deployment by using Kustomize.
As the student user on the workstation machine, use the lab command to prepare
your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start multicontainer-kustomize
Instructions
You are asked to configure two versions of your deployment files: one for development and the other for production deployment. The deployments differ in terms of performance and number of running pods. Find the requirements of each environment in the following table:
| Environment | Pods | Memory | CPU Limit |
|---|---|---|---|
dev
| 1 | 128Mi | 128m |
prod
| 2 | 256Mi | 256m |
Log in to Red Hat OpenShift.
Log in to OpenShift as the developer user.
[student@workstation ~]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Ensure that you use the multicontainer-kustomize project.
[student@workstation ~]$ oc project multicontainer-kustomize
Already on project "multicontainer-kustomize" on server "https://api.ocp4.example.com:6443".Review the Famous Quotes deployment files.
Change to the ~/DO288/labs/multicontainer-kustomize directory.
[student@workstation ~]$cd ~/DO288/labs/multicontainer-kustomize...no output expected...
Review the deployment.yaml file.
[student@workstation multicontainer-kustomize]$ cat deployment.yaml
...output omitted...Create the Kustomize directory structure.
Create the famous-kustomize main directory.
Then, change to that directory.
[student@workstation multicontainer-kustomize]$mkdir famous-kustomize...no output expected...[student@workstation multicontainer-kustomize]$cd famous-kustomize...no output expected...
Create the base directory.
Then, populate it with the YAML file that you have customized.
[student@workstation famous-kustomize]$mkdir base...no output expected...[student@workstation famous-kustomize]$cp ../deployment.yaml base/...no output expected...
Create the base/kustomization.yaml description file for the base definition with the following content:
resources: - deployment.yaml
Test the base definition.
Deploy the base definition.
[student@workstation famous-kustomize]$ oc apply -k base
configmap/famousapp-mariadb created
...output omitted...Wait until the application deployment becomes available.
[student@workstation famous-kustomize]$oc get deploymentsNAME READY UP-TO-DATE AVAILABLE AGEfamousapp-famouschart 1/11 1 10s
Call the /random endpoint of the deployed application.
[student@workstation famous-kustomize]$ curl -s \
famousapp-famouschart-multicontainer-kustomize.apps.ocp4.example.com/random
5: Imagination is more important than knowledge.
- Albert EinsteinCreate the dev environment definition.
Create the development overlay directory.
[student@workstation famous-kustomize]$mkdir -p overlays/dev...no output expected...
Create the overlays/dev/replica_limits.yaml file with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: famousapp-famouschart
spec:
replicas: 1
template:
spec:
containers:
- name: famouschart
resources:
limits:
memory: "128Mi"
cpu: "128m"Create the overlays/dev/kustomization.yaml file with the following content:
bases: - ../../base patches: - replica_limits.yaml
The preceding kustomization.yaml file applies the replica_limits.yaml file to the base deployment.
Render the Kustomize dev overlay.
[student@workstation famous-kustomize]$oc kustomize overlays/dev | \ grep -A49 "kind: Deployment"...output omitted... ports: - containerPort: 8000 name: http protocol: TCP readinessProbe: httpGet: path: / port: httpresources: limits: cpu: 128m memory: 128MisecurityContext: {} securityContext: {}
Create the prod environment definition.
Copy the dev environment overlay to the prod directory.
[student@workstation famous-kustomize]$cp -R overlays/dev overlays/prod...no output expected...
Modify the configuration in the overlays/prod/replica_limits.yaml file:
apiVersion: apps/v1 kind: Deployment metadata: name: famousapp-famouschart spec: replicas:2template: spec: containers: - name: famouschart resources: limits: memory:"256Mi"cpu:"256m"
Render the Kustomize prod overlay.
[student@workstation famous-kustomize]$oc kustomize overlays/prod | \ grep -A49 "kind: Deployment"...output omitted... spec: replicas:2...output omitted... readinessProbe: httpGet: path: / port: httpresources: limits: cpu: 256m memory: 256MisecurityContext: {} securityContext: {}