Bookmark this page

Lab: Deploy Packaged Applications

Deploy a Helm chart

Deploy an application with Kustomize

Expose a service using MetalLB

Outcomes

  • Deploy an application from a chart.

  • Deploy an application from a Kustomize layer.

  • Configure an application to connect to the MySQL database.

If you did not previously reset your workstation and server machines, then save any work that you want to keep from earlier exercises on those machines, and reset them now.

Use the lab command to prepare your system for this exercise.

This command ensures that the cluster API is reachable and prepares the environment for the exercise.

[student@workstation ~]$ lab start compreview-package

Specifications

Deploy an application that uses a database by using a Helm chart and Kustomization files. Access the application by using a route.

  • Use the developer user with the developer password for this exercise.

  • Use a compreview-package project for all the resources.

  • Deploy a MySQL database by using the mysql-persistent Helm chart in the http://helm.ocp4.example.com/charts repository. Use the latest version in the repository, and the default resource names that the chart generates.

  • Use Kustomize in the /home/student/DO280/labs/compreview-package/roster/ path to deploy the application. Add a new Kustomize production overlay that adds probes to the application.

    The /home/student/DO280/solutions/compreview-package/roster/overlays/production/ directory contains the solution kustomization.yaml file and the patch-roster-prod.yaml file.

  • Deploy the overlay.

  • Verify that the application creates a route, and that the application is available through the route by using the TLS/SSL protocol (HTTPS).

  1. Add the classroom Helm repository at http://helm.ocp4.example.com/charts and examine its contents.

    1. Use the helm repo list command to list the repositories that are configured for the student user.

      [student@workstation ~]$ helm repo list
      Error: no repositories to show

      If the do280-repo repository is present, then continue to the next step. Otherwise, add the repository.

      [student@workstation ~]$ helm repo add \
        do280-repo http://helm.ocp4.example.com/charts
      "do280-repo" has been added to your repositories
    2. Use the helm search command to list all the charts in the repository.

      [student@workstation ~]$ helm search repo
      NAME                       	CHART VERSION	APP VERSION	DESCRIPTION
      do280-repo/mysql-persistent	0.0.2        	0.0.2      	This content is...
      ...output omitted...

      The mysql-persistent chart is in the classroom repository. This chart is a copy of a chart from the https://github.com/openshift-helm-charts/charts/ repository.

  2. Create a compreview-package project.

    1. Log in to the cluster as the developer user with the developer password.

      [student@workstation ~]$ oc login -u developer -p developer \
        https://api.ocp4.example.com:6443
      Login successful.
      ...output omitted...
    2. Create the compreview-package project.

      [student@workstation ~]$ oc new-project compreview-package
      Now using project "compreview-package" on server "https://api.ocp4.example.com:6443".
      ...output omitted...
  3. Deploy the do280-repo/mysql-persistent chart.

    1. Use the helm install command to create a release of the do280-repo/mysql-persistent chart.

      [student@workstation ~]$ helm install roster-database do280-repo/mysql-persistent
      ...output omitted...
    2. Use the watch command to verify that the pods are running. Wait for the mysql-1-deploy pod to show a Completed status.

      [student@workstation ~]$ watch oc get pods
      NAME                      READY   STATUS      RESTARTS   AGE
      mysql-1-7w5bn             1/1     Running     0          150m
      mysql-1-deploy            0/1     Completed   0          150m

      Press Ctrl+C to exit the watch command.

  4. Examine the provided Kustomize configuration and the deployed chart, and verify that the production overlay generates a deployment, service, route, configuration map, and a secret. Verify that the patch-roster-prod.yaml patch file applies the liveness and readiness probes to the roster deployment.

    1. Change to the /home/student/DO280/labs/compreview-package/ directory.

      [student@workstation ~]$ cd DO280/labs/compreview-package/
    2. Use the tree command to examine the directory structure.

      [student@workstation compreview-package]$ tree
      .
      └── roster
          ├── base
          │   ├── configmap.yaml
          │   ├── kustomization.yaml
          │   ├── roster-deployment.yaml
          │   ├── roster-route.yaml
          │   ├── roster-service.yaml
          │   └── secret.yaml
          └── overlays
              └── production
                  ├── kustomization.yaml
      	    └── patch-roster-prod.yaml
      
      4 directories, 8 files

      The Kustomization configuration includes a deployment, a route, and a service.

    3. Examine the roster/base/roster-deployment.yaml file.

      apiVersion: apps/v1
      kind: Deployment
      metadata:
      ...output omitted...
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: roster
        template:
      ...output omitted...
          spec:
            containers:
            - image: registry.ocp4.example.com:8443/redhattraining/do280-roster:v1
              name: do280-roster
              envFrom:
              - configMapRef:
                  name: roster
              - secretRef:
                  name: roster
      ...output omitted...

      The deployment does not set any configuration to access the database. The deployment extracts environment variables from a roster configuration map and a roster secret.

    4. Use the oc kustomize command to verify that the production overlay generates a deployment, service, route, configuration map, and a secret, and configures the liveness and readiness probes to the roster deployment.

      [student@workstation compreview-package]$ oc kustomize roster/overlays/production/
      apiVersion: v1
      data:
      ...output omitted...
      kind: ConfigMap
      ...output omitted...
      ---
      apiVersion: v1
      kind: Secret
      ...output omitted...
      ---
      apiVersion: v1
      kind: Service
      ...output omitted...
      ---
      apiVersion: apps/v1
      kind: Deployment
      metadata:
      ...output omitted...
      spec:
      ...output omitted...
        template:
      ...output omitted...
          spec:
            containers:
      ...output omitted...
      	livenessProbe:
                initialDelaySeconds: 20
                periodSeconds: 30
                tcpSocket:
                  port: 9090
                timeoutSeconds: 3
              name: roster
      	ports:
      	- containerPort: 9090
      	  protocol: TCP
              readinessProbe:
                initialDelaySeconds: 3
                periodSeconds: 10
                tcpSocket:
                  port: 9090
                timeoutSeconds: 3
      ---
      apiVersion: route.openshift.io/v1
      kind: Route
      ...output omitted...
  5. Deploy the Kustomize files.

    1. Use the oc apply -k command to deploy the production overlay.

      [student@workstation compreview-package]$ oc apply -k roster/overlays/production/
      configmap/roster created
      secret/roster created
      service/roster created
      deployment.apps/roster created
      route.route.openshift.io/roster unchanged
    2. Use the watch command to verify that the pods are running. Wait for the roster pod to show the Running status.

      [student@workstation compreview-package]$ watch oc get pods
      NAME                      READY   STATUS      RESTARTS   AGE
      ...output omitted...
      roster-5d4888dc6f-4rp4n   1/1     Running     0          166m

      Press Ctrl+C to exit the watch command.

    3. Use the oc get route command to obtain the application URL.

      [student@workstation compreview-package]$ oc get route
      NAME     HOST/PORT                                         ...
      roster   roster-compreview-package.apps.ocp4.example.com   ...
    4. Open a web browser and navigate to https://roster-compreview-package.apps.ocp4.example.com. Use the TLS/SSL protocol (HTTPS). The application is displayed.

    5. Change to the home directory.

      [student@workstation compreview-package]$ cd

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade compreview-package

Finish

As the student user 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 compreview-package
Revision: do280-4.14-08d11e1