Skip to content

Commit

Permalink
Adding sources for the technical peer review track (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdewinne authored Aug 1, 2023
1 parent 882ee37 commit e5c42f1
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 0 deletions.
34 changes: 34 additions & 0 deletions instruqt/technical-peer-review/01-getting-started/assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
slug: getting-started
id: vuw8ykv0xxbc
type: challenge
title: Getting Started
teaser: Why is the pod not running
notes:
- type: text
contents: |-
This track uses a single node Kubernetes cluster on a sandbox virtual machine.
Please wait while we boot the VM for you and start Kubernetes.
## Objectives
In this track, this is what you'll learn:
- Find the problem
- Fix the problem
tabs:
- title: Shell
type: terminal
hostname: kubernetes-vm
difficulty: basic
timelimit: 1800
---

👋 Introduction
===============

Use the terminal and `kubectl` to understand why the pod is not running.

🏁 Solution
===========

Use the terminal and `kubectl` to redeploy the pod and make sure it is in a running state.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Create the nginx deployment
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
initContainers:
- image: busybox
name: coffee
command:
- sh
- -c
- sleeeep 10
containers:
- image: nginx
name: nginx
EOF
42 changes: 42 additions & 0 deletions instruqt/technical-peer-review/02-exposing-nginx/assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
slug: exposing-nginx
id: mrlgykq8y8ed
type: challenge
title: Expose the NGINX service
teaser: Why can't I access nginx
notes:
- type: text
contents: You've just deployed NGINX. Now let's try browsing it
tabs:
- title: Shell
type: terminal
hostname: kubernetes-vm
- title: NodePort
type: service
hostname: kubernetes-vm
path: /
port: 30001
difficulty: basic
timelimit: 1800
---

👋 Introduction
===============

Use the terminal, the browser tab and `kubectl` to understand why you can't access nginx.

🏁 Solution
===========

Use the terminal and `kubectl` to fix the issue.

<details>
<summary>Hint</summary>

```
k create svc nodeport my-nginx --node-port=30001 --tcp=80 --dry-run=client -o yaml > nginxsvc.yaml
```

And change the `selecter` to use `app: nginx`.

</details>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx
name: nginx
spec:
ports:
- port: 80
protocol: TCP
selector:
app: nginx
type: ClusterIP
EOF
57 changes: 57 additions & 0 deletions instruqt/technical-peer-review/03-awkward-scaling/assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
slug: awkward-scaling
id: rkvhyttuiahw
type: challenge
title: Awkward scaling
teaser: Someone did some weird way of scaling
notes:
- type: text
contents: Something is wrong with the pods. Try to understand why, and find one
or multiple ways of fixing it.
tabs:
- title: Shell
type: terminal
hostname: kubernetes-vm
- title: NodePort
type: service
hostname: kubernetes-vm
path: /
port: 30001
difficulty: basic
timelimit: 1800
---

👋 Introduction
===============

Use the terminal and `kubectl` to understand why you sometimes can't access nginx.
Use the `check-nginx.sh` script to verify if nginx is running.

<details>
<summary>The script</summary>

```
#!/bin/bash
echo "Checking nginx"
for i in {1..10}
do
curl -s -o /dev/null -w "Response: %{http_code} %{errormsg}" localhost:30001
echo ""
sleep 2
done
```
</details>

🏁 Solution
===========

Use the terminal and `kubectl` to fix the issue.

<details>
<summary>Hint</summary>

Someone created a second deployment instead of changing the number of replicas. Use `k scale`? Or edit the deployment?
Also this is a great opportunity to talk about `readinessProbes` and `livenessProbes`.

</details>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Create the nginx deployment
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-extra
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
initContainers:
- image: busybox
name: coffee
command:
- sh
- -c
- sleep 10
containers:
- image: busybox
name: milk
command:
- sh
- -c
- sleep 1800
EOF

# Create the check-nginx.sh script
cat <<EOF > check-nginx.sh
#!/bin/bash
echo "Checking nginx"
for i in {1..10}
do
curl -s -o /dev/null -w "Response: %{http_code} %{errormsg}" localhost:30001
echo ""
sleep 2
done
EOF
chmod +x check-nginx.sh
6 changes: 6 additions & 0 deletions instruqt/technical-peer-review/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3"
virtualmachines:
- name: kubernetes-vm
image: instruqt/k3s-v1-25-0
shell: /bin/bash
machine_type: n1-standard-2
11 changes: 11 additions & 0 deletions instruqt/technical-peer-review/track.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
slug: technical-peer-review
id: nrjmvv9bmgky
title: Technical Peer Review
teaser: Solve some k8s problems
description: Solve some k8s problems with the help from Replicated engineers.
icon: https://cdn.instruqt.com/assets/templates/kubernetes.png
tags: []
owner: replicated
developers:
- [email protected]
checksum: "15144180777240178116"
17 changes: 17 additions & 0 deletions instruqt/technical-peer-review/track_scripts/setup-kubernetes-vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Wait for the Instruqt host bootstrap to finish
until [ -f /opt/instruqt/bootstrap/host-bootstrap-completed ]
do
sleep 1
done

# Wait for the Kubernetes API server to become available
while ! curl --silent --fail --output /dev/null http://localhost:8001/api
do
sleep 1
done

# Enable bash completion for kubectl
echo "source /usr/share/bash-completion/bash_completion" >> /root/.bashrc
echo "complete -F __start_kubectl k" >> /root/.bashrc

0 comments on commit e5c42f1

Please sign in to comment.