Skip to content

Exercise 2 - Deployments

You describe the desired state of your application in a Deployment by specifying the number of replicas and a Pod template. The Deployment involve a ReplicaSet to manage the Pods in the background.

The ReplicaSet ensures that specified number of Pod replicas are running all the time. If a Pod crashes or is deleted the ReplicaSet creates new instances up to the defined number. Likewise, if there are more Pods running than desired, it deletes as many as necessary.

Check out the OpenShift or Kubernetes Documentation for more information about Deployments and ReplicaSets.

Note

For each exercise you can choose and only have to do either the 'Web Console' or the 'Command Line Interface (CLI)' section in oder to complete the exercise.

Create a Deployment

  1. Switch to the 'Administrator' view using the dropdown menu at .
  2. Navigate to 'Workloads' → 'Deployments' .
  3. Switch to the your project using the dropdown menu at . In each of the exercise make sure that you are in your project context before you are making any changes.
  4. Press 'Create Deployment' .
  5. Copy the following Deployment definition file to the editor :
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: httpd
      labels:
        app: httpd
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: httpd
      template:
        metadata:
          labels:
            app: httpd
        spec:
          containers:
          - name: httpd-24
            image: ubi9/httpd-24:latest
    
    More detailed information about the Deployment definition file can be found in the Tab at .
  6. Press 'Create' .

Inspect a Deployment

Note

If you have created the Deployment using the CLI:

  1. Repeat the steps 1 - 3 of the 'Create a Deployment' task above
  2. Open the 'Deployment Details' by clicking on the Deployment name in the 'Deployments' overview table.
  1. Check the 'Details' and status of the Pods of a Deployment by moving the mouse over the blue circle . The status should be 'Running' after a couple of seconds.
  2. Additionally check the 'Pods' and the 'Events'
What is the difference between the Pod that was created manually and the one that was created by the Deployment?

Solution:

The Pod created from the Deployment have a random name.

Example:

httpd-12cf4d11ce-p9w5h
The Deployment adds a random string (e.g. 12cf4d11ce) to the deployment name while creating the ReplicaSet. The ReplicaSet itself adds another random string to the each Pod (e.g. p9w5h).

What happens if you delete a pod by opening in the 'Pods' tab and clicking ?

Solution:

The ReplicaSet of the Deployment automatically creates a new Pod. The same would happen if the application in the container of the Pod crashed or terminated. Check the 'Events' again to see what happend.

Scale a Deployment

  1. Scale the Deployment to have another Pod of the application to achieve a redundant and stable setup by clicking on the up arrow at .
  2. Wait until both Pods are running and inspect agin the 'Events' .

Important

At the beginning of the exercise make sure that you are in your project context.

oc project <project name> 

Create a Deployment

  1. Create a Deployment of the Apache HTTP Server using the oc create command:
    oc create deployment httpd --image ubi9/httpd-24:latest
    
    The output of the command should look this:
    [~] $ oc create deployment httpd --image ubi9/httpd-24:latest
    deployment.apps/httpd created
    

Inspect a Deployment

  1. Let's verify the state of the Deployment that you have created using oc get and oc describe.

    oc get deployments -o wide
    
    oc describe deployment <deployment name>
    

  2. Inspect the pods the Deployment has created.

    oc get pods
    
    oc get pods -o wide
    

    What is the difference between the Pod that was created manually and the one that was created by the Deployment?

    Solution:

    The Pod created from the Deployment have a random name.

    Example:

    httpd-12cf4d11ce-p9w5h
    
    The Deployment adds a random string (e.g. 12cf4d11ce) to the deployment name while creating the ReplicaSet. The ReplicaSet itself adds another random string to the each Pod (e.g. p9w5h).

    What happens if you delete a pod using oc delete pod <pod name>?

    Solution:

    The ReplicaSet of the Deployment automatically creates a new Pod. The same would happen if the application in the container of the Pod crashed or terminated.

  3. Also check the 'Inspect a Deployment' section for the Web Console.

Scale a Deployment

  1. Scale the Deployment to have another Pod of the application to achieve a redundant and stable setup.
    oc scale deployment <deployment name> --replicas=2
    
  2. Inspect the Deployment and pods again.