Bookmark this page

Guided Exercise: The Kustomize CLI

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:

EnvironmentPodsMemoryCPU Limit
dev 1128Mi128m
prod 2256Mi256m
  1. Log in to Red Hat OpenShift.

    1. 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...
    2. 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".
  2. Review the Famous Quotes deployment files.

    1. Change to the ~/DO288/labs/multicontainer-kustomize directory.

      [student@workstation ~]$ cd ~/DO288/labs/multicontainer-kustomize
      ...no output expected...
    2. Review the deployment.yaml file.

      [student@workstation multicontainer-kustomize]$ cat deployment.yaml
      ...output omitted...
  3. Create the Kustomize directory structure.

    1. 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...
    2. 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...
    3. Create the base/kustomization.yaml description file for the base definition with the following content:

      resources:
      - deployment.yaml
  4. Test the base definition.

    1. Deploy the base definition.

      [student@workstation famous-kustomize]$ oc apply -k base
      configmap/famousapp-mariadb created
      ...output omitted...
    2. Wait until the application deployment becomes available.

      [student@workstation famous-kustomize]$ oc get deployments
      NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
      famousapp-famouschart      1/1     1            1           10s
    3. 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 Einstein
  5. Create the dev environment definition.

    1. Create the development overlay directory.

      [student@workstation famous-kustomize]$ mkdir -p overlays/dev
      ...no output expected...
    2. 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"
    3. 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.

    4. 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: http
              resources:
                limits:
                  cpu: 128m
                  memory: 128Mi
              securityContext: {}
            securityContext: {}
  6. Create the prod environment definition.

    1. Copy the dev environment overlay to the prod directory.

      [student@workstation famous-kustomize]$ cp -R overlays/dev overlays/prod
      ...no output expected...
    2. Modify the configuration in the overlays/prod/replica_limits.yaml file:

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: famousapp-famouschart
      spec:
        replicas: 2
        template:
          spec:
            containers:
              - name: famouschart
                resources:
                  limits:
                    memory: "256Mi"
                    cpu: "256m"
    3. 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: http
              resources:
                limits:
                  cpu: 256m
                  memory: 256Mi
              securityContext: {}
            securityContext: {}

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish multicontainer-kustomize

Revision: do288-4.12-0d49506