Skip to content

Commit

Permalink
feat: add networking workshop
Browse files Browse the repository at this point in the history
  • Loading branch information
seifrajhi committed Feb 18, 2024
1 parent 779885b commit 033d4a0
Show file tree
Hide file tree
Showing 2,104 changed files with 846,696 additions and 0 deletions.
125 changes: 125 additions & 0 deletions networking-workshop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Workshops


Open source series of workshops delivered by the Gravitational team.

* [Docker 101 workshop](docker.md)
* [Kubernetes 101 workshop using Minikube and Mattermost](k8s101.md)
* [Kubernetes production patterns](k8sprod.md)
* [Kubernetes security patterns](k8ssecurity.md)
* [Kubernetes custom resources](crd/crd.md)
* [Gravity fire drill exercises](firedrills.md)
* [Gravity logging (Gravity 5.5 and earlier)](logging-5.x.md)
* [Gravity logging (Gravity 6.0 and later)](logging-6.x.md)
* [Gravity monitoring & alerts (Gravity 5.5 and earlier)](monitoring-5.x.md)
* [Gravity monitoring & alerts (Gravity 6.0 and later)](monitoring-6.x.md)
* [Gravity networking and network troubleshooting](gravity_networking.md)
* [Gravity upgrade (5.5)](upgrade-5.x.md)
* [Gravity upgrade (7.0)](gravity_upgrade.md)

## Installation

### Requirements

You will need a Linux or macOS box with at least `7GB` of RAM and `20GB` of free disk space available.

### Docker

For Linux: follow instructions provided [here](https://docs.docker.com/engine/installation/linux/).

If you have macOS (Yosemite or newer), please download Docker for Mac [here](https://download.docker.com/mac/stable/Docker.dmg).

*Older docker package for OSes older than Yosemite -- Docker Toolbox located [here](https://www.docker.com/products/docker-toolbox).*

### Hypervisor

#### HyperKit [macOS only]

HyperKit is a lightweight macOS hypervisor which minikube supports out of the box and which should be
already installed on your machine if you have Docker for Desktop installed.

More information: <https://minikube.sigs.k8s.io/docs/reference/drivers/hyperkit/>.

Alternatively, install VirtualBox like described below.

#### KVM2 [Linux only]

Follow the instructions here: <https://minikube.sigs.k8s.io/docs/reference/drivers/kvm2/>.

Alternatively, install VirtualBox like described below.

#### VirtualBox [both macOS and Linux]

Let’s install VirtualBox.

Get latest stable version from <https://www.virtualbox.org/wiki/Downloads>.

**Note:** When using Ubuntu you may need to disable Secure Boot. For an alternative approach to installing with Secure Boot enabled,
follow the guide [here](https://torstenwalter.de/virtualbox/ubuntu/2019/06/13/install-virtualbox-ubuntu-secure-boot.html).

### Kubectl

For macOS:

curl -O https://storage.googleapis.com/kubernetes-release/release/v1.16.2/bin/darwin/amd64/kubectl \
&& chmod +x kubectl && sudo mv kubectl /usr/local/bin/

For Linux:

curl -O https://storage.googleapis.com/kubernetes-release/release/v1.16.2/bin/linux/amd64/kubectl \
&& chmod +x kubectl && sudo mv kubectl /usr/local/bin/

### Minikube

For macOS:

curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.5.1/minikube-darwin-amd64 \
&& chmod +x minikube && sudo mv minikube /usr/local/bin/

For Linux:

curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.5.1/minikube-linux-amd64 \
&& chmod +x minikube && sudo mv minikube /usr/local/bin/

Also, you can install drivers for various VM providers to optimize your minikube VM performance.
Instructions can be found here: <https://github.com/kubernetes/minikube/blob/master/docs/drivers.md>.

### Xcode and local tools

Xcode will install essential console utilities for us. You can install it from the App Store.

## Set up cluster using minikube

To run cluster:

**macOS**

```bash
# starts minikube
$ minikube start --kubernetes-version=v1.16.2
# this command should work
$ kubectl get nodes
# use docker from minikube
$ eval $(minikube docker-env)
# this command to check connectivity
$ docker ps
```

**Linux**

```bash
# starts minikube
$ minikube start --kubernetes-version=v1.16.2 --vm-driver=kvm2
# this command should work
$ kubectl get nodes
# use docker from minikube
$ eval $(minikube docker-env)
# this command to check connectivity
$ docker ps
```

## Configure registry

```shell
kubectl create -f registry.yaml
```
8 changes: 8 additions & 0 deletions networking-workshop/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server {
listen 80;
server_name localhost;

location / {
return 200 'hello, Kubernetes!';
}
}
32 changes: 32 additions & 0 deletions networking-workshop/crd/assets/controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# This deployment launches a custom controller that monitors Nginx custom
# resources and spins up respective nginx pods.
#
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-controller
namespace: default
labels:
app: nginx-controller
spec:
replicas: 1
selector:
matchLabels:
app: nginx-controller
template:
metadata:
labels:
app: nginx-controller
spec:
containers:
- name: controller
image: quay.io/gravitational/nginx-controller:0.0.1
imagePullPolicy: Always
volumeMounts:
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
hostPath:
path: /tmp
29 changes: 29 additions & 0 deletions networking-workshop/crd/assets/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# This custom resource spec defines a new Kubernetes resource kind Nginx.
#
# Nginx resource, when created, will trigger a creation of a single nginx pod
# if the custom controller is running inside the cluster.
#
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: nginxes.training.example.com
spec:
group: training.example.com
version: v1
scope: Namespaced
names:
kind: Nginx
plural: nginxes
singular: nginx
shortNames:
- ng
validation:
openAPIV3Schema:
required: ["spec"]
properties:
spec:
required: ["version"]
properties:
version:
type: "string"
15 changes: 15 additions & 0 deletions networking-workshop/crd/assets/nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# This spec describes a custom resource of kind Nginx.
#
# The custom resource kind is defined in crd.yaml and should be registered
# before this resource can be created.
#
# When created, this resource will trigger creation of a single nginx pod, if
# the custom controller is running in the cluster.
#
apiVersion: training.example.com/v1
kind: Nginx
metadata:
name: nginx-web
spec:
version: 1.17.5
1 change: 1 addition & 0 deletions networking-workshop/crd/controller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
controller
5 changes: 5 additions & 0 deletions networking-workshop/crd/controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM quay.io/gravitational/debian-tall:0.0.1
LABEL maintainer="Gravitational <[email protected]>"
LABEL description="Kubernetes controller for custom resource Nginx."
ADD ./controller /controller
ENTRYPOINT ["/controller"]
Loading

0 comments on commit 033d4a0

Please sign in to comment.