From 769b335b22c312762c38d79f7b33ff1e25393f22 Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Thu, 10 Feb 2022 13:00:51 +1100 Subject: [PATCH 1/6] wip --- README.md | 2 +- kubernetes/readme.md | 92 +++++++++++++++++++++++++++- kubernetes/tutorial/deploy.yaml | 42 +++++++++++++ kubernetes/tutorial/ingress.yaml | 18 ++++++ kubernetes/tutorial/service.yaml | 14 +++++ kubernetes/tutorial/statefulset.yaml | 66 ++++++++++++++++++++ 6 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 kubernetes/tutorial/deploy.yaml create mode 100644 kubernetes/tutorial/ingress.yaml create mode 100644 kubernetes/tutorial/service.yaml create mode 100644 kubernetes/tutorial/statefulset.yaml diff --git a/README.md b/README.md index 7e0d3f5..c1abbf7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The Ultimate Swiss Army knife for DevOps, Developers and Platform Engineers | Steps | Playlist :tv: | Source :octocat: | |---|---|---| -| Learn Kubernetes :snowflake: | Kubernetes Guide | [source](./kubernetes/readme.md) | +| [Learn Kubernetes](./kubernetes/README.md) :snowflake: | Kubernetes Guide | [source](./kubernetes/readme.md) | | Learn about CI/CD tools :whale: | CI/CD Guide | | | | | Deploy Kubernetes to the cloud :partly_sunny: | Cloud Guide | [source](./kubernetes/cloud/readme.md) | | Monitoring Kubernetes :mag: | Cloud Guide | [source](./monitoring/prometheus/kubernetes/readme.md) | diff --git a/kubernetes/readme.md b/kubernetes/readme.md index ec223a0..28d8735 100644 --- a/kubernetes/readme.md +++ b/kubernetes/readme.md @@ -1,4 +1,94 @@ -# Kubernetes Development Series YouTube :hammer::wrench: +# Learn Kubernetes YouTube :hammer::wrench: + +This guide is aimed to fast-track your Kubernetes learning by focusing on a practical hands-on overview guide.
+This means, not too much of a deepdive, but enough to get a feel for the required building blocks of Kubernetes so you can align it with a real world problem that you are trying to solve.
+ +The problem: "I want to adopt Kubernetes"
+The problem: "I have some common existing infrastructure" + +Our focus: Solving the problem by learning each building block +in order to port our infrastructure to Kubernetes. + +## Docker installation + +* Install Docker [here](https://docs.docker.com/get-docker/) + +## Run Kubernetes + +* Install `kubectl` to work with kubernetes + +We'll head over to the [kubernetes](https://kubernetes.io/docs/tasks/tools/) site to download `kubectl` + +* Install the `kind` binary + +You will want to head over to the [kind](https://kind.sigs.k8s.io/) site + +* Create a cluster + +``` +kind create cluster +``` + +## Namespaces + +``` +kubectl create namespace cms +``` + +## Deployments + +* Deployment [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) + +cd kubernetes\tutorial + +``` +kubectl -n cms apply -f deploy.yaml +kubectl -n cms get pods + +kubectl -n cms port-forward 80 +``` + +[Environment Variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/) for pods + +## Secrets + +``` +kubectl -n cms create secret generic wordpress ` +--from-literal WORDPRESS_DB_HOST=mysql ` +--from-literal WORDPRESS_DB_USER=exampleuser ` +--from-literal WORDPRESS_DB_PASSWORD=examplepassword ` +--from-literal WORDPRESS_DB_NAME=exampledb + +kubectl -n cms get secret + +``` +[How to use](https://kubernetes.io/docs/concepts/configuration/secret/) secrets in pods + +Apply changes to our deployment + +``` +kubectl -n cms apply -f deploy.yaml +``` + +We can `port-forward` again, and notice an error connecting to the database because the database does not exist + +# Statefulset + +Statefulset [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) + +# Storage Class + +StorageClass [documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/) + +# Services + +Services [documentation](https://kubernetes.io/docs/concepts/services-networking/service/) + +Let's deploy our `mysql` using what we learnt above: + +``` +kubectl -n cms apply -f .\statefulset.yaml +``` ## Full playlist diff --git a/kubernetes/tutorial/deploy.yaml b/kubernetes/tutorial/deploy.yaml new file mode 100644 index 0000000..da0992b --- /dev/null +++ b/kubernetes/tutorial/deploy.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wordpress-deployment + labels: + app: wordpress +spec: + replicas: 2 + selector: + matchLabels: + app: wordpress + template: + metadata: + labels: + app: wordpress + spec: + containers: + - name: wordpress + image: wordpress + ports: + - containerPort: 80 + env: + - name: WORDPRESS_DB_HOST + valueFrom: + secretKeyRef: + name: wordpress + key: WORDPRESS_DB_HOST + - name: WORDPRESS_DB_USER + valueFrom: + secretKeyRef: + name: wordpress + key: WORDPRESS_DB_USER + - name: WORDPRESS_DB_PASSWORD + valueFrom: + secretKeyRef: + name: wordpress + key: WORDPRESS_DB_PASSWORD + - name: WORDPRESS_DB_NAME + valueFrom: + secretKeyRef: + name: wordpress + key: WORDPRESS_DB_PASSWORD \ No newline at end of file diff --git a/kubernetes/tutorial/ingress.yaml b/kubernetes/tutorial/ingress.yaml new file mode 100644 index 0000000..c1fd0c7 --- /dev/null +++ b/kubernetes/tutorial/ingress.yaml @@ -0,0 +1,18 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: wordpress + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + ingressClassName: nginx + rules: + - http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: wordpress + port: + number: 80 diff --git a/kubernetes/tutorial/service.yaml b/kubernetes/tutorial/service.yaml new file mode 100644 index 0000000..c13b8eb --- /dev/null +++ b/kubernetes/tutorial/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: wordpress + labels: + app: wordpress +spec: + ports: + - port: 80 + name: db + targetPort: 80 + type: ClusterIP + selector: + app: wordpress \ No newline at end of file diff --git a/kubernetes/tutorial/statefulset.yaml b/kubernetes/tutorial/statefulset.yaml new file mode 100644 index 0000000..28eebc2 --- /dev/null +++ b/kubernetes/tutorial/statefulset.yaml @@ -0,0 +1,66 @@ +apiVersion: v1 +kind: Service +metadata: + name: mysql + labels: + app: mysql +spec: + ports: + - port: 3306 + name: db + type: ClusterIP + selector: + app: mysql +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: mysql +spec: + selector: + matchLabels: + app: mysql # has to match .spec.template.metadata.labels + serviceName: "mysql" + replicas: 1 + template: + metadata: + labels: + app: mysql # has to match .spec.selector.matchLabels + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: mysql + image: mysql:5.7 + ports: + - containerPort: 3306 + name: db + env: + - name: MYSQL_DATABASE + valueFrom: + secretKeyRef: + name: wordpress + key: WORDPRESS_DB_PASSWORD + - name: MYSQL_USER + valueFrom: + secretKeyRef: + name: wordpress + key: WORDPRESS_DB_USER + - name: MYSQL_PASSWORD + valueFrom: + secretKeyRef: + name: wordpress + key: WORDPRESS_DB_PASSWORD + - name: MYSQL_RANDOM_ROOT_PASSWORD + value: "1" + volumeMounts: + - name: db + mountPath: /var/lib/mysql + volumeClaimTemplates: + - metadata: + name: db + spec: + accessModes: [ "ReadWriteOnce" ] + storageClassName: "standard" + resources: + requests: + storage: 500Mi \ No newline at end of file From 1cd21b939b657ee4574c53f4bc1de63aa2c12819 Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Sun, 20 Mar 2022 07:53:10 +1100 Subject: [PATCH 2/6] wip --- kubernetes/readme.md | 90 ------------------ kubernetes/tutorials/basics/README.md | 92 +++++++++++++++++++ .../basics/yaml}/deploy.yaml | 0 .../basics/yaml}/ingress.yaml | 0 .../basics/yaml}/service.yaml | 0 .../basics/yaml}/statefulset.yaml | 0 6 files changed, 92 insertions(+), 90 deletions(-) create mode 100644 kubernetes/tutorials/basics/README.md rename kubernetes/{tutorial => tutorials/basics/yaml}/deploy.yaml (100%) rename kubernetes/{tutorial => tutorials/basics/yaml}/ingress.yaml (100%) rename kubernetes/{tutorial => tutorials/basics/yaml}/service.yaml (100%) rename kubernetes/{tutorial => tutorials/basics/yaml}/statefulset.yaml (100%) diff --git a/kubernetes/readme.md b/kubernetes/readme.md index 28d8735..6f2a68e 100644 --- a/kubernetes/readme.md +++ b/kubernetes/readme.md @@ -1,95 +1,5 @@ # Learn Kubernetes YouTube :hammer::wrench: -This guide is aimed to fast-track your Kubernetes learning by focusing on a practical hands-on overview guide.
-This means, not too much of a deepdive, but enough to get a feel for the required building blocks of Kubernetes so you can align it with a real world problem that you are trying to solve.
- -The problem: "I want to adopt Kubernetes"
-The problem: "I have some common existing infrastructure" - -Our focus: Solving the problem by learning each building block -in order to port our infrastructure to Kubernetes. - -## Docker installation - -* Install Docker [here](https://docs.docker.com/get-docker/) - -## Run Kubernetes - -* Install `kubectl` to work with kubernetes - -We'll head over to the [kubernetes](https://kubernetes.io/docs/tasks/tools/) site to download `kubectl` - -* Install the `kind` binary - -You will want to head over to the [kind](https://kind.sigs.k8s.io/) site - -* Create a cluster - -``` -kind create cluster -``` - -## Namespaces - -``` -kubectl create namespace cms -``` - -## Deployments - -* Deployment [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) - -cd kubernetes\tutorial - -``` -kubectl -n cms apply -f deploy.yaml -kubectl -n cms get pods - -kubectl -n cms port-forward 80 -``` - -[Environment Variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/) for pods - -## Secrets - -``` -kubectl -n cms create secret generic wordpress ` ---from-literal WORDPRESS_DB_HOST=mysql ` ---from-literal WORDPRESS_DB_USER=exampleuser ` ---from-literal WORDPRESS_DB_PASSWORD=examplepassword ` ---from-literal WORDPRESS_DB_NAME=exampledb - -kubectl -n cms get secret - -``` -[How to use](https://kubernetes.io/docs/concepts/configuration/secret/) secrets in pods - -Apply changes to our deployment - -``` -kubectl -n cms apply -f deploy.yaml -``` - -We can `port-forward` again, and notice an error connecting to the database because the database does not exist - -# Statefulset - -Statefulset [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) - -# Storage Class - -StorageClass [documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/) - -# Services - -Services [documentation](https://kubernetes.io/docs/concepts/services-networking/service/) - -Let's deploy our `mysql` using what we learnt above: - -``` -kubectl -n cms apply -f .\statefulset.yaml -``` - ## Full playlist Kubernetes Guide diff --git a/kubernetes/tutorials/basics/README.md b/kubernetes/tutorials/basics/README.md new file mode 100644 index 0000000..e943d50 --- /dev/null +++ b/kubernetes/tutorials/basics/README.md @@ -0,0 +1,92 @@ +# Tutorial: The Basics + +This guide is aimed to fast-track your Kubernetes learning by focusing on a practical hands-on overview guide.
+ +
+The problem: "I want to adopt Kubernetes"
+The problem: "I have some common existing infrastructure" +
+ +Our focus: Solving the problem by learning each building block +in order to port our infrastructure to Kubernetes. + +## Docker installation + +* Install Docker [here](https://docs.docker.com/get-docker/) + +## Run Kubernetes + +* Install `kubectl` to work with kubernetes + +We'll head over to the [kubernetes](https://kubernetes.io/docs/tasks/tools/) site to download `kubectl` + +* Install the `kind` binary + +You will want to head over to the [kind](https://kind.sigs.k8s.io/) site + +* Create a cluster + +``` +kind create cluster +``` + +## Namespaces + +``` +kubectl create namespace cms +``` + +## Deployments + +* Deployment [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) + +cd kubernetes\tutorial + +``` +kubectl -n cms apply -f deploy.yaml +kubectl -n cms get pods + +kubectl -n cms port-forward 80 +``` + +[Environment Variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/) for pods + +## Secrets + +``` +kubectl -n cms create secret generic wordpress ` +--from-literal WORDPRESS_DB_HOST=mysql ` +--from-literal WORDPRESS_DB_USER=exampleuser ` +--from-literal WORDPRESS_DB_PASSWORD=examplepassword ` +--from-literal WORDPRESS_DB_NAME=exampledb + +kubectl -n cms get secret + +``` +[How to use](https://kubernetes.io/docs/concepts/configuration/secret/) secrets in pods + +Apply changes to our deployment + +``` +kubectl -n cms apply -f deploy.yaml +``` + +We can `port-forward` again, and notice an error connecting to the database because the database does not exist + +# Statefulset + +Statefulset [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) + +# Storage Class + +StorageClass [documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/) + +# Services + +Services [documentation](https://kubernetes.io/docs/concepts/services-networking/service/) + +Let's deploy our `mysql` using what we learnt above: + +``` +kubectl -n cms apply -f .\statefulset.yaml +``` diff --git a/kubernetes/tutorial/deploy.yaml b/kubernetes/tutorials/basics/yaml/deploy.yaml similarity index 100% rename from kubernetes/tutorial/deploy.yaml rename to kubernetes/tutorials/basics/yaml/deploy.yaml diff --git a/kubernetes/tutorial/ingress.yaml b/kubernetes/tutorials/basics/yaml/ingress.yaml similarity index 100% rename from kubernetes/tutorial/ingress.yaml rename to kubernetes/tutorials/basics/yaml/ingress.yaml diff --git a/kubernetes/tutorial/service.yaml b/kubernetes/tutorials/basics/yaml/service.yaml similarity index 100% rename from kubernetes/tutorial/service.yaml rename to kubernetes/tutorials/basics/yaml/service.yaml diff --git a/kubernetes/tutorial/statefulset.yaml b/kubernetes/tutorials/basics/yaml/statefulset.yaml similarity index 100% rename from kubernetes/tutorial/statefulset.yaml rename to kubernetes/tutorials/basics/yaml/statefulset.yaml From 7384d560d97ce5dc727036af388e25c5d12d340d Mon Sep 17 00:00:00 2001 From: Marcel Dempers Date: Fri, 15 Apr 2022 15:52:17 +1000 Subject: [PATCH 3/6] updates k8s --- kubernetes/tutorials/basics/README.md | 211 +++++++++++++++--- .../basics/dockerfiles/mysql.dockerfile | 5 + .../basics/dockerfiles/wordpress.dockerfile | 5 + kubernetes/tutorials/basics/yaml/deploy.yaml | 2 +- .../tutorials/basics/yaml/statefulset.yaml | 17 +- 5 files changed, 203 insertions(+), 37 deletions(-) create mode 100644 kubernetes/tutorials/basics/dockerfiles/mysql.dockerfile create mode 100644 kubernetes/tutorials/basics/dockerfiles/wordpress.dockerfile diff --git a/kubernetes/tutorials/basics/README.md b/kubernetes/tutorials/basics/README.md index e943d50..285271f 100644 --- a/kubernetes/tutorials/basics/README.md +++ b/kubernetes/tutorials/basics/README.md @@ -2,6 +2,10 @@ This guide is aimed to fast-track your Kubernetes learning by focusing on a practical hands-on overview guide.
+When learning Kubernetes, you usually have an idea of some existing system you own and manage, or a website that you are building.
+ +The challenge is understanding which Kubernetes building blocks you need in order to run your workloads on Kubernetes
+
The problem: "I want to adopt Kubernetes"
The problem: "I have some common existing infrastructure" @@ -10,11 +14,113 @@ This guide is aimed to fast-track your Kubernetes learning by focusing on a prac Our focus: Solving the problem by learning each building block in order to port our infrastructure to Kubernetes. -## Docker installation +## Understanding Containers + +Before even looking at Kubernetes, you need to have a general understanding of containers like `docker`. +Your workloads need to fit in containers in order to be shipped on Kubernetes.
+Containers also have a bunch of assumptions that you need to meet. + +* Defining the container - `Dockerfile` +* Serving traffic - Exposing ports +* Configuration - mount config files & secrets or `env` variables +* Data persistence - When a container is terminated, everything inside the container is gone +* Container entrypoint - The main process that runs in the container. Your app + + +### Docker installation * Install Docker [here](https://docs.docker.com/get-docker/) +* Let's take a look at [Wordpress on Docker Hub](https://hub.docker.com/_/wordpress) +* Build our docker file -## Run Kubernetes +## Create Network + +``` +docker network create wordpress +``` + +## Build & Test container images + + ### Wordpress example +``` +cd kubernetes\tutorials\basics\ + +docker build -f dockerfiles/wordpress.dockerfile . -t aimvector/wordpress-example + +``` + +* Run our Wordpress container + +``` +docker run -it --rm -p 80:80 --net wordpress aimvector/wordpress-example +``` + +The wordpress container will be visible on port 80 on `http://localhost/` + +### MySQL example + +* We need a database, let's take a look at [MySQL on Docker Hub](https://hub.docker.com/_/mysql) +* Build our MySQl container image + +``` +docker build -f dockerfiles/mysql.dockerfile . -t aimvector/mysql-example +``` + +* How do we run our MySQL ? + +We need to understand that databases require storage and state +Just like installing software on a server, it will store its files in some +directory. Mysql stores its files under `/var/lib/mysql` + +* We need a volume mount + +Let's see how to run this in docker + +``` +mkdir data + +docker run --rm -d ` +--name mysql ` +--net wordpress ` +-e MYSQL_DATABASE=exampledb ` +-e MYSQL_USER=exampleuser ` +-e MYSQL_PASSWORD=examplepassword ` +-e MYSQL_RANDOM_ROOT_PASSWORD=1 ` +-v ${PWD}/data:/var/lib/mysql ` +aimvector/mysql-example + +# we can see the container with +docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +92cde663a3f5 aimvector/mysql-example "docker-entrypoint.s…" 5 seconds ago Up 3 seconds 3306/tcp, 33060/tcp mysql + +``` + +* Run Wordpress and connect it to MySQL + +``` +docker run -d ` +--rm ` +-p 80:80 ` +--name wordpress ` +--net wordpress ` +-e WORDPRESS_DB_HOST=mysql ` +-e WORDPRESS_DB_USER=exampleuser ` +-e WORDPRESS_DB_PASSWORD=examplepassword ` +-e WORDPRESS_DB_NAME=exampledb ` +aimvector/wordpress-example +``` + +### Clean up + +``` +docker rm -f wordpress +docker rm -f mysql +docker network rm wordpress +rm data +``` + +## Run Kubernetes Locally * Install `kubectl` to work with kubernetes @@ -27,7 +133,7 @@ You will want to head over to the [kind](https://kind.sigs.k8s.io/) site * Create a cluster ``` -kind create cluster +kind create cluster --image kindest/node:v1.23.5 ``` ## Namespaces @@ -36,23 +142,23 @@ kind create cluster kubectl create namespace cms ``` -## Deployments - -* Deployment [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) - -cd kubernetes\tutorial - -``` -kubectl -n cms apply -f deploy.yaml -kubectl -n cms get pods - -kubectl -n cms port-forward 80 -``` +## Configmaps [Environment Variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/) for pods +[How to use](https://kubernetes.io/docs/concepts/configuration/configmap/) configmaps + +``` +kubectl -n cms create configmap mysql ` +--from-literal MYSQL_RANDOM_ROOT_PASSWORD=1 + +kubectl -n cms get configmaps +``` + ## Secrets +[How to use](https://kubernetes.io/docs/concepts/configuration/secret/) secrets in pods + ``` kubectl -n cms create secret generic wordpress ` --from-literal WORDPRESS_DB_HOST=mysql ` @@ -60,33 +166,80 @@ kubectl -n cms create secret generic wordpress ` --from-literal WORDPRESS_DB_PASSWORD=examplepassword ` --from-literal WORDPRESS_DB_NAME=exampledb +kubectl -n cms create secret generic mysql ` +--from-literal MYSQL_USER=exampleuser ` +--from-literal MYSQL_PASSWORD=examplepassword ` +--from-literal MYSQL_DATABASE=exampledb + + kubectl -n cms get secret ``` -[How to use](https://kubernetes.io/docs/concepts/configuration/secret/) secrets in pods -Apply changes to our deployment +## Deployments + +* Deployment [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) + +cd kubernetes\tutorials\basics ``` -kubectl -n cms apply -f deploy.yaml +kubectl -n cms apply -f yaml/deploy.yaml +kubectl -n cms get pods ``` -We can `port-forward` again, and notice an error connecting to the database because the database does not exist - -# Statefulset - -Statefulset [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) - -# Storage Class - -StorageClass [documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/) - # Services Services [documentation](https://kubernetes.io/docs/concepts/services-networking/service/) +# Storage Class + +StorageClass [documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/) + +``` +kubectl get storageclass +``` + +# Statefulset + +Statefulset [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) + Let's deploy our `mysql` using what we learnt above: ``` -kubectl -n cms apply -f .\statefulset.yaml +kubectl -n cms apply -f yaml/statefulset.yaml + +kubectl -n cms get pods +``` + +## Persistent Volumes + +[Documentation](https://kubernetes.io/docs/concepts/storage/persistent-volumes/) + +## Port Forwarding + +We can access private service endpoints or pods using `port-forward` : + +``` +kubectl -n cms get pods +kubectl -n cms port-forward 80 +``` + +## Public Traffic + +In order to make our site public, its common practise to expose web servers via
+a proxy or API gateway.
+In Kubernetes, an Ingress is used. + +## Ingress + +To use an ingress, we need an ingress controller + +``` +kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/cloud/deploy.yaml +``` + +Create an Ingress + +``` +kubectl -n cms apply -f yaml/ingress.yaml ``` diff --git a/kubernetes/tutorials/basics/dockerfiles/mysql.dockerfile b/kubernetes/tutorials/basics/dockerfiles/mysql.dockerfile new file mode 100644 index 0000000..53d0d5d --- /dev/null +++ b/kubernetes/tutorials/basics/dockerfiles/mysql.dockerfile @@ -0,0 +1,5 @@ +FROM mysql:5.7 + +# make any changes to MySQL installation + +EXPOSE 3306 \ No newline at end of file diff --git a/kubernetes/tutorials/basics/dockerfiles/wordpress.dockerfile b/kubernetes/tutorials/basics/dockerfiles/wordpress.dockerfile new file mode 100644 index 0000000..42accc8 --- /dev/null +++ b/kubernetes/tutorials/basics/dockerfiles/wordpress.dockerfile @@ -0,0 +1,5 @@ +FROM wordpress:5.9-apache + +#COPY files , plugins, install extra stuff + +EXPOSE 80 \ No newline at end of file diff --git a/kubernetes/tutorials/basics/yaml/deploy.yaml b/kubernetes/tutorials/basics/yaml/deploy.yaml index da0992b..74ffc3e 100644 --- a/kubernetes/tutorials/basics/yaml/deploy.yaml +++ b/kubernetes/tutorials/basics/yaml/deploy.yaml @@ -39,4 +39,4 @@ spec: valueFrom: secretKeyRef: name: wordpress - key: WORDPRESS_DB_PASSWORD \ No newline at end of file + key: WORDPRESS_DB_NAME \ No newline at end of file diff --git a/kubernetes/tutorials/basics/yaml/statefulset.yaml b/kubernetes/tutorials/basics/yaml/statefulset.yaml index 28eebc2..b80c23e 100644 --- a/kubernetes/tutorials/basics/yaml/statefulset.yaml +++ b/kubernetes/tutorials/basics/yaml/statefulset.yaml @@ -38,20 +38,23 @@ spec: - name: MYSQL_DATABASE valueFrom: secretKeyRef: - name: wordpress - key: WORDPRESS_DB_PASSWORD + name: mysql + key: MYSQL_DATABASE - name: MYSQL_USER valueFrom: secretKeyRef: - name: wordpress - key: WORDPRESS_DB_USER + name: mysql + key: MYSQL_USER - name: MYSQL_PASSWORD valueFrom: secretKeyRef: - name: wordpress - key: WORDPRESS_DB_PASSWORD + name: mysql + key: MYSQL_PASSWORD - name: MYSQL_RANDOM_ROOT_PASSWORD - value: "1" + valueFrom: + configMapKeyRef: + name: mysql + key: MYSQL_RANDOM_ROOT_PASSWORD volumeMounts: - name: db mountPath: /var/lib/mysql From 77df499742666a63ba5b0fa564e43484896c6673 Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Fri, 15 Apr 2022 22:40:42 +1000 Subject: [PATCH 4/6] k8s guide update --- kubernetes/tutorials/basics/README.md | 4 ++++ kubernetes/tutorials/basics/yaml/ingress.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/kubernetes/tutorials/basics/README.md b/kubernetes/tutorials/basics/README.md index 285271f..1080be2 100644 --- a/kubernetes/tutorials/basics/README.md +++ b/kubernetes/tutorials/basics/README.md @@ -236,6 +236,10 @@ To use an ingress, we need an ingress controller ``` kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/cloud/deploy.yaml + +kubectl -n ingress-nginx get pods + +kubectl -n ingress-nginx --address 0.0.0.0 port-forward svc/ingress-nginx-controller 80 ``` Create an Ingress diff --git a/kubernetes/tutorials/basics/yaml/ingress.yaml b/kubernetes/tutorials/basics/yaml/ingress.yaml index c1fd0c7..77ccdc0 100644 --- a/kubernetes/tutorials/basics/yaml/ingress.yaml +++ b/kubernetes/tutorials/basics/yaml/ingress.yaml @@ -7,7 +7,7 @@ metadata: spec: ingressClassName: nginx rules: - - http: + - http: paths: - path: / pathType: Prefix From f5e528ceca5253601b3da2779d7a69203269dee5 Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Fri, 22 Apr 2022 20:02:04 +1000 Subject: [PATCH 5/6] updates --- kubernetes/tutorials/basics/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kubernetes/tutorials/basics/README.md b/kubernetes/tutorials/basics/README.md index 1080be2..6e351da 100644 --- a/kubernetes/tutorials/basics/README.md +++ b/kubernetes/tutorials/basics/README.md @@ -1,4 +1,4 @@ -# Tutorial: The Basics +# Kubernetes Tutorial: The Basics This guide is aimed to fast-track your Kubernetes learning by focusing on a practical hands-on overview guide.
@@ -120,6 +120,12 @@ docker network rm wordpress rm data ``` +## Kubernetes Tools: kubectl + +To manage and work with Kubernetes, you need `kubectl`
+Let's grab that from [here](https://kubernetes.io/docs/tasks/tools/) + + ## Run Kubernetes Locally * Install `kubectl` to work with kubernetes From 3724902e8ee21be6e8fc95301e1a3d42b0b4666c Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Tue, 3 May 2022 19:19:15 +1000 Subject: [PATCH 6/6] k8s tutorial updates --- .gitignore | 1 + kubernetes/tutorials/basics/README.md | 5 +++++ kubernetes/tutorials/basics/yaml/deploy.yaml | 2 +- kubernetes/tutorials/basics/yaml/service.yaml | 2 +- kubernetes/tutorials/basics/yaml/statefulset.yaml | 2 +- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1742f88..2777ada 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ kubernetes/shipa/installs/shipa-helm-chart-1.1.1/ messaging/kafka/data/* kubernetes/portainer/volume* kubernetes/rancher/volume/* +kubernetes/portainer/business/volume* diff --git a/kubernetes/tutorials/basics/README.md b/kubernetes/tutorials/basics/README.md index 6e351da..0d3797f 100644 --- a/kubernetes/tutorials/basics/README.md +++ b/kubernetes/tutorials/basics/README.md @@ -197,6 +197,11 @@ kubectl -n cms get pods Services [documentation](https://kubernetes.io/docs/concepts/services-networking/service/) +``` +kubectl -n cms apply -f .\yaml\service.yaml +kubectl -n cms get svc +``` + # Storage Class StorageClass [documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/) diff --git a/kubernetes/tutorials/basics/yaml/deploy.yaml b/kubernetes/tutorials/basics/yaml/deploy.yaml index 74ffc3e..121fefe 100644 --- a/kubernetes/tutorials/basics/yaml/deploy.yaml +++ b/kubernetes/tutorials/basics/yaml/deploy.yaml @@ -16,7 +16,7 @@ spec: spec: containers: - name: wordpress - image: wordpress + image: aimvector/wordpress-example ports: - containerPort: 80 env: diff --git a/kubernetes/tutorials/basics/yaml/service.yaml b/kubernetes/tutorials/basics/yaml/service.yaml index c13b8eb..87112d9 100644 --- a/kubernetes/tutorials/basics/yaml/service.yaml +++ b/kubernetes/tutorials/basics/yaml/service.yaml @@ -7,7 +7,7 @@ metadata: spec: ports: - port: 80 - name: db + name: wordpress targetPort: 80 type: ClusterIP selector: diff --git a/kubernetes/tutorials/basics/yaml/statefulset.yaml b/kubernetes/tutorials/basics/yaml/statefulset.yaml index b80c23e..c377d64 100644 --- a/kubernetes/tutorials/basics/yaml/statefulset.yaml +++ b/kubernetes/tutorials/basics/yaml/statefulset.yaml @@ -30,7 +30,7 @@ spec: terminationGracePeriodSeconds: 10 containers: - name: mysql - image: mysql:5.7 + image: aimvector/mysql-example ports: - containerPort: 3306 name: db