Skip to content

Commit 4ec286c

Browse files
authored
Merge pull request #43 from Namanv0509/k8s-workshop
k8s workshop
2 parents e43d9a6 + 4d272b2 commit 4ec286c

File tree

92 files changed

+3042
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3042
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "Kubernetes Workshop"
3+
description: "This learning path provides an introduction to Kubernetes, focusing on its architecture, components, and how to manage clusters effectively."
4+
weight: 1
5+
banner: "/98e16360-a366-4b78-8e0a-031da07fdacb/images/kubernetes-icon.svg"
6+
---
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
docType: "Course"
3+
title: "Concepts"
4+
description: "Kubernetes Basic Concepts"
5+
courseTitle: "Concepts"
6+
weight: 1
7+
banner: "/98e16360-a366-4b78-8e0a-031da07fdacb/images/kubernetes-icon.svg"
8+
---
9+
10+
## History
11+
12+
Kubernetes also called *k8s* (a "k" followed by 8 chars and a "s") or simply *kube* means "Helmsman" in Greek. It is a container orchestrator inspired by Google Borg System which were orchestrating billions of containers on Google infrastructure.
13+
14+
Version *v1.0.0* of Kubernetes was released in July 2015, the last version as of today (October 2024) is *v1.31.1*. The release cycle is quite fast with 3 minor releases per year.
15+
16+
## Main functionalities
17+
18+
Kubernetes is a container orchestrator offering main functionalities, such as:
19+
20+
- Management of applications running in containers
21+
- Self-healing
22+
- Service discovery
23+
- Usage of Secrets and Configurations
24+
- Long-running process and batch jobs
25+
- Role Based Access Control (RBAC)
26+
- Storage Orchestration
27+
28+
## Manages applications in production
29+
30+
![environments]({{< usestatic "k8s-workshop/environments.png" >}})
31+
## Major project in the open-source ecosystem
32+
33+
Kubernetes is the first graduated project within the [CNCF](https://cncf.io/projects), it was followed by major players like [etcd](https://etcd.io) and [Prometheus](https://prometheus.io/)
34+
35+
![cncf]({{< usestatic "k8s-workshop/cncf.png" >}})
36+
## What is a Kubernetes cluster made of ?
37+
38+
A Kubernetes cluster is composed of nodes, where a node is either a virtual machine or a bare metal server. A node can belong to the Control Plane which run processes in charge of managing the cluster and the applications running on it. Or, a node can be a Worker dedicated to run Pods, a group of containers sharing a network stack and storage.
39+
40+
![cluster]({{< usestatic "k8s-workshop/cluster.png" >}})
41+
42+
## How to access a cluster
43+
44+
A cluster usually comes with a kubeconfig file which contains all the information to communicate with the cluster API Server. This file can be used to configure the standard *kubectl* binary to manage the cluster. The kubeconfig file can also be used with tools like [k9s](https://k9scli.io/), [Mirantis Lens](https://k8slens.dev/), ... which give a higher level view of the cluster.
45+
46+
![access]({{< usestatic "k8s-workshop/access.png" >}})
47+
48+
## Various workload resources for different use cases
49+
50+
To run a Pod we often rely on a higher level resource, instead of running it directly. The workload resources are:
51+
52+
- Deployment : web server
53+
- DaemonSet : one agent per node
54+
- Job / CronJob : batch
55+
- StatefulSet : stateful application
56+
57+
![workloads]({{< usestatic "k8s-workshop/workloads.png" >}})
58+
59+
A request that reaches a Service is load-balanced between the exposed Pods
60+
61+
![service]({{< usestatic "k8s-workshop/service.png" >}})
62+
63+
64+
A Pod can use several resources
65+
66+
- ConfigMap : contains configuration data
67+
- Secret : contains sensitive data
68+
- PersistentVolumeClaim / PersistentVolume : storage management
69+
70+
![pod-resources]({{< usestatic "k8s-workshop/pod-resources.png" >}})
71+
72+
73+
## Several types of resources
74+
75+
![summary]({{< usestatic "k8s-workshop/summary.png" >}})
76+
77+
## An application runs in a Namespace
78+
79+
80+
![namespace]({{< usestatic "k8s-workshop/namespace.png" >}})
81+
82+
## Resource creation
83+
84+
Each resource is defined in a YAML specification which is sent to the API Server using the kubectl binary.
85+
86+
```yaml
87+
apiVersion: v1
88+
kind: Pod
89+
metadata:
90+
name: www
91+
spec:
92+
containers:
93+
- name: www
94+
image: nginx:1.24
95+
```
96+
97+
```bash
98+
kubectl apply -f www.yaml
99+
```
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
docType: "Course"
3+
title: "Creation of a local cluster"
4+
description: "Create Local kubernetes cluster"
5+
courseTitle: "Creation of a local cluster"
6+
weight: 2
7+
banner: "/98e16360-a366-4b78-8e0a-031da07fdacb/images/kubernetes-icon.svg"
8+
9+
---
10+
11+
Using a local cluster is very handy to get started with Kubernetes, or to test things quickly. In this example, we'll use [K3s](https://k3s.io), a lightweight Kubernetes distribution (5 's' fewer than k8s :) ). K3s is a certified distribution, well-suited for IoT, Edge computing, and which works well with huge servers.
12+
13+
In this section, we'll use [Multipass](https://multipass.run) to create an Ubuntu virtual machine and install k3s on this one. Multipass is a convenient tool to launch Ubuntu VM on Mac/Linux/Windows; it can be installed on your environment following [the documentation](https://canonical.com/multipass/install).
14+
15+
#### info
16+
We use Multipass as it is handy and lightweight, but feel free to use the tool you're the most comfortable with. If you use another tool, please just make sure to adapt the commands below.
17+
18+
19+
We'll only create a single node Kubernetes cluster in this section.
20+
21+
## Pre-requisite
22+
23+
On your local machine, [install kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl). It's the essential tool for communicating with a Kubernetes cluster from the command line.
24+
25+
## Creating an Ubuntu VM
26+
27+
Once you've installed Multipass, create an Ubuntu 24.04 virtual machine named *k3s* with 2G of memory allocated. This process should take a few tens of seconds.
28+
29+
```bash
30+
multipass launch --name k3s --memory 2G
31+
```
32+
33+
Then get the IP address of the newly created VM.
34+
35+
```bash
36+
IP=$(multipass info k3s | grep IP | awk '{print $2}')
37+
```
38+
39+
## Installing k3s
40+
41+
Run the following command to install k3s the VM. This process should also take a few tens of seconds.
42+
43+
```bash
44+
multipass exec k3s -- bash -c "curl -sfL https://get.k3s.io | sh -"
45+
```
46+
47+
#### info
48+
The command `curl -sfL https://get.k3s.io | sh -`, used to install k3s comes from the official [k3s](https://k3s.io) documentation
49+
50+
51+
## Getting the kubeconfig file
52+
53+
Retrieve the configuration file generated during Kubernetes installation on your local machine:
54+
55+
```bash
56+
multipass exec k3s sudo cat /etc/rancher/k3s/k3s.yaml > k3s.cfg.tmp
57+
```
58+
59+
In this file, replace the local IP address (127.0.0.1) with the IP address of the VM you created. This IP address should be in the $IP environment variable.
60+
61+
```bash
62+
cat k3s.cfg.tmp | sed "s/127.0.0.1/$IP/" > k3s.cfg
63+
```
64+
65+
Then set the *KUBECONFIG* environment variable to point to the previously retrieved configuration file:
66+
67+
```bash
68+
export KUBECONFIG=$PWD/k3s.cfg
69+
```
70+
71+
### Info
72+
This environment variable configures the *kubectl* binary so it can communicate with the cluster.
73+
74+
75+
You can now communicate with the cluster's API Server.
76+
77+
List of the cluster's node (only one in this example):
78+
79+
```bash
80+
kubectl get nodes
81+
```
82+
83+
List of the Pods running in the cluster:
84+
85+
```bash
86+
kubectl get pods -A
87+
```
88+
89+
You'll use this local cluster to do the exercises of the [next section](../resources/).
90+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
docType: "Course"
3+
title: "Resources"
4+
description: "Learn and Practice Main Resources"
5+
courseTitle: "Resources"
6+
weight: 3
7+
banner: "/98e16360-a366-4b78-8e0a-031da07fdacb/images/kubernetes-icon.svg"
8+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
docType: "Chapter"
3+
title: "Configuration"
4+
description: "Manage configuration and sensitive data"
5+
courseTitle: "Configuration"
6+
weight: 1
7+
banner: "/98e16360-a366-4b78-8e0a-031da07fdacb/images/configuration.png"
8+
---

0 commit comments

Comments
 (0)