Skip to content

Commit

Permalink
Update lab4
Browse files Browse the repository at this point in the history
  • Loading branch information
mincong-h committed Nov 3, 2024
1 parent f57b855 commit b245972
Showing 1 changed file with 75 additions and 69 deletions.
144 changes: 75 additions & 69 deletions docs/lab-4.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Deployment and Networking in Kubernetes

Lab Session 4 - 4 Nov, 2024
Lab Session 4 - 7 Nov, 2024

# Introduction

Expand All @@ -14,35 +14,21 @@ To submit the answers to this lab session, please fill in your answers
in this document in-place. This should be done before the beginning of
the next course.

## Prerequisite

If you are using the computer of ESIGELEC, the Docker Desktop is
preinstalled, but you need to enable the Kubernetes feature in Docker
Desktop’s settings. If you are using your personal computer, please
download Docker Desktop from the official website of Docker, Inc. and
enable the Kubernetes feature.

<https://www.docker.com/products/docker-desktop/>

Before starting the lab session, please clear all Kubernetes resources
from your Kubernetes Cluster by using the button “Reset Kubernetes
Cluster” in your Docker Desktop (Settings \> Kubernetes).

<!-- I don't add more details because they should already have the software installed. -->

## Exercise 1 - ReplicaSet

Create a new ReplicaSet with 2 replicas and the Docker image
`nginx:1.26` and call this resource `nginx`. Use labels `app:nginx`,
`team=${team}`, and `tier=frontend` for both the ReplicaSet and the
underlying pods. The pods should expose the container port 80 to receive
incoming traffic. The name of the container should also be “nginx”.
Persist the Kubernetes manifest (YAML file) in the Git repository of
your team under the `k8s` directory.
`nginx:1.26` and call this resource `nginx`. Use labels
`school=esigelec`, `app=nginx`, `team=${team}`, and `tier=frontend` for
both the ReplicaSet and the underlying pods. The pods should expose the
container port 80 to receive incoming traffic. The name of the container
should also be “nginx”. Persist the Kubernetes manifest (YAML file) in
the Git repository of your team under the `k8s` directory as file
`replicaset-nginx.yaml`.



    *\[answer: commit to the Git repository of your team\]*
    *\[answer: optional. Commit code changes directly under the `k8s`
directory.\]*



Expand Down Expand Up @@ -73,24 +59,36 @@ now? Why?
## Exercise 2 - Deployment

Create a new Deployment with 2 replicas using the Docker image
`weekend-server` that you built in the previous lab session and call
this deployment `weekend-server`. Use labels `app:weekend-server`,
`team=${team}`, and `tier=backend` for both the Deployment and the
underlying pods. Persist the Kubernetes manifest (YAML file) in the Git
repository of your team under the `k8s` directory.
`mincongclassroom/weekend-server-${team}` that you built in the previous
lab session and call this deployment `weekend-server`. Use labels
`school=esigelec`, `app=weekend-server`, `team=${team}`, and
`tier=backend` for both the Deployment and the underlying pods. Persist
the Kubernetes manifest (YAML file) in the Git repository of your team
under the `k8s` directory as file `deployment-weekend-server.yaml`.

In addition to the changes above, please also

- Add environment variable `APP_TEAM` in the manifest to describe your
team for the container
- Add environment variable `APP_AUTHORS` in the manifest to describe
yourselves as authors of the container. The format should be
“Firstname1 LASTNAME1, Firstname2 LASTNAME2”, such as “Emmanuel
MACRON”.
- Propagate the pod name to the container.



    *\[answer: commit to the Git repository of your team\]*
    *\[answer: optional. Commit code changes directly under the `k8s`
directory.\]*





Do you see a ReplicaSet related to your deployment? If yes, write down
the name of the ReplicaSet, else please share your thoughts. Hint: you
can use the command `kubectl get` all\` to list all the resources in
your Kubernetes cluster under the current namespace.
can use the command `kubectl get all` to list all the resources in your
Kubernetes cluster under the current namespace.



Expand All @@ -110,26 +108,59 @@ Scale up the deployment to 3 replicas and share the command below.



Upgrade the Docker image of the weekend-server deployment by setting the
image to another version that you built. Roll out this change and
observe the status of the Pods, ReplicaSet, and Deployment. Please
describe your observation here.



    *\[answer\]*





Inspect the revision history of your deployment.



    *\[answer\]*





What if you specify an image that does not exist?

    *\[answer\]*





## Exercise 3 - Service

Provide a networking solution for weekend-server application so that
this deployment is exposed to other resources inside the Kubernetes
cluster. Please ensure that access is only granted for resources within
the Kubernetes cluster, access from external systems is not allowed.
Persist the Kubernetes manifest (YAML file) in the Git repository of
your team under the `k8s` directory.
your team under the `k8s` directory as file
`service-weekend-server.yaml`.



    *\[answer: commit to the Git repository of your team\]*
    *\[answer: optional. Commit code changes directly under the `k8s`
directory.\]*





Port forward to that service by listening to port 8080 of your machine
and forwarding data to port 80 of the service (`8080:80`) to verify that
the service is working as expected. Please share the kubectl command.
and forwarding data to your service weekend-server to verify that the
service is working as expected. Please share the kubectl command.



Expand All @@ -140,15 +171,16 @@ the service is working as expected. Please share the kubectl command.


Use another to verify that this is working as expected. Please create a
helper pod with the image busybox using the command below. Try to use
different DNS queries to send HTTP requests to the service. Reminder:
after starting the busybox, you can use `wget` command with output to
stdout (`-O-`), followed by the URL to make an HTTP request. You can
exit the pod by pressing CTRL + D (‘D’ stands for disconnect).
helper pod with the image
[curlimages/curl](https://hub.docker.com/r/curlimages/curl) using the
command below. Try to use different DNS queries to send HTTP requests to
the service. Reminder: after starting the curl image, you can use `curl`
command followed by the URL to make an HTTP request. You can exit the
pod by pressing CTRL + D (‘D’ stands for disconnect).

``` sh
kubectl run busybox --image=busybox --restart=Never --rm -it -- /bin/sh
# wget -O- ${URL}
kubectl run curl-pod --image=curlimages/curl --restart=Never --rm -it -- /bin/sh
# curl ${URL}
```

Here is a reminder of different expressions:
Expand All @@ -167,29 +199,3 @@ Please provide the commands and results below.
    *\[answer\]*





## Exercise 4 - Upgrade Docker Image

Upgrade the Docker image of the deployment by setting the image to
`nginx:1.27` and roll out this change. Observe the status of the Pods
and ReplicaSet. Please describe your observation here.



    *\[answer\]*





Inspect the revision history of your deployment.



    *\[answer\]*




0 comments on commit b245972

Please sign in to comment.