mirror of
https://github.com/marcel-dempers/docker-development-youtube-series.git
synced 2025-06-06 17:01:30 +00:00
Merge branch 'master' of https://github.com/marcel-dempers/docker-development-youtube-series
This commit is contained in:
commit
3d107eacfb
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,4 +13,4 @@ kubernetes/shipa/installs/shipa-helm-chart-1.1.1/
|
||||
messaging/kafka/data/*
|
||||
kubernetes/portainer/volume*
|
||||
kubernetes/rancher/volume/*
|
||||
kubernetes/portainer/business/volume-ce
|
||||
kubernetes/portainer/business/volume*
|
||||
|
@ -8,7 +8,7 @@ The Ultimate Swiss Army knife for DevOps, Developers and Platform Engineers
|
||||
|
||||
| Steps | Playlist :tv: | Source :octocat: |
|
||||
|---|---|---|
|
||||
| Learn Kubernetes :snowflake: | <a href="https://www.youtube.com/playlist?list=PLHq1uqvAteVvUEdqaBeMK2awVThNujwMd" title="Kubernetes"><img src="https://i.ytimg.com/vi/8h4FoWK7tIA/hqdefault.jpg" width="50%" alt="Kubernetes Guide" /></a> | [source](./kubernetes/readme.md) |
|
||||
| [Learn Kubernetes](./kubernetes/README.md) :snowflake: | <a href="https://www.youtube.com/playlist?list=PLHq1uqvAteVvUEdqaBeMK2awVThNujwMd" title="Kubernetes"><img src="https://i.ytimg.com/vi/8h4FoWK7tIA/hqdefault.jpg" width="50%" alt="Kubernetes Guide" /></a> | [source](./kubernetes/readme.md) |
|
||||
| Learn about CI/CD tools :whale: | <a href="https://www.youtube.com/playlist?list=PLHq1uqvAteVsSsrnZimHEf7NJ1MlRhQUj" title="CI/CD"><img src="https://i.ytimg.com/vi/myCcJJ_Fk10/hqdefault.jpg" width="50%" alt="CI/CD Guide" /></a> | | | |
|
||||
| Deploy Kubernetes to the cloud :partly_sunny: | <a href="https://www.youtube.com/playlist?list=PLHq1uqvAteVsUhzNBkn-rPzXtPNpJu1-k" title="Cloud K8s"><img src="https://i.ytimg.com/vi/3jA9EfkSAUU/hqdefault.jpg" width="50%" alt="Cloud Guide" /></a> | [source](./kubernetes/cloud/readme.md) |
|
||||
| Monitoring Kubernetes :mag: | <a href="https://www.youtube.com/playlist?list=PLHq1uqvAteVuEXCrRkPFWLXRKWNLOVUHn" title="Cloud K8s"><img src="https://i.ytimg.com/vi/5o37CGlNLr8/hqdefault.jpg" width="50%" alt="Cloud Guide" /></a> | [source](./monitoring/prometheus/kubernetes/readme.md) |
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Kubernetes Development Series <img src="https://www.shareicon.net/data/128x128/2017/04/11/883708_media_512x512.png" alt="YouTube" width="5%" height="5%"> :hammer::wrench:
|
||||
# Learn Kubernetes <img src="https://www.shareicon.net/data/128x128/2017/04/11/883708_media_512x512.png" alt="YouTube" width="5%" height="5%"> :hammer::wrench:
|
||||
|
||||
## Full playlist
|
||||
|
||||
|
260
kubernetes/tutorials/basics/README.md
Normal file
260
kubernetes/tutorials/basics/README.md
Normal file
@ -0,0 +1,260 @@
|
||||
# Kubernetes Tutorial: The Basics
|
||||
|
||||
This guide is aimed to fast-track your Kubernetes learning by focusing on a practical hands-on overview guide. </br>
|
||||
|
||||
When learning Kubernetes, you usually have an idea of some existing system you own and manage, or a website that you are building. </br>
|
||||
|
||||
The challenge is understanding which Kubernetes building blocks you need in order to run your workloads on Kubernetes </br>
|
||||
|
||||
<hr/>
|
||||
<b>The problem:</b> "I want to adopt Kubernetes" </br>
|
||||
<b>The problem:</b> "I have some common existing infrastructure"
|
||||
<hr/>
|
||||
|
||||
<b>Our focus:</b> Solving the problem by learning each building block
|
||||
in order to port our infrastructure to Kubernetes.
|
||||
|
||||
## 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. </br>
|
||||
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
|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||
## Kubernetes Tools: kubectl
|
||||
|
||||
To manage and work with Kubernetes, you need `kubectl` </br>
|
||||
Let's grab that from [here](https://kubernetes.io/docs/tasks/tools/)
|
||||
|
||||
|
||||
## Run Kubernetes Locally
|
||||
|
||||
* 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 --image kindest/node:v1.23.5
|
||||
```
|
||||
|
||||
## Namespaces
|
||||
|
||||
```
|
||||
kubectl create namespace cms
|
||||
```
|
||||
|
||||
## 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 `
|
||||
--from-literal WORDPRESS_DB_USER=exampleuser `
|
||||
--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
|
||||
|
||||
```
|
||||
|
||||
## Deployments
|
||||
|
||||
* Deployment [documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
|
||||
|
||||
cd kubernetes\tutorials\basics
|
||||
|
||||
```
|
||||
kubectl -n cms apply -f yaml/deploy.yaml
|
||||
kubectl -n cms get pods
|
||||
```
|
||||
|
||||
# Services
|
||||
|
||||
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/)
|
||||
|
||||
```
|
||||
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 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 <pod-name> 80
|
||||
```
|
||||
|
||||
## Public Traffic
|
||||
|
||||
In order to make our site public, its common practise to expose web servers via </br>
|
||||
a proxy or API gateway. </br>
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
```
|
||||
kubectl -n cms apply -f yaml/ingress.yaml
|
||||
```
|
5
kubernetes/tutorials/basics/dockerfiles/mysql.dockerfile
Normal file
5
kubernetes/tutorials/basics/dockerfiles/mysql.dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM mysql:5.7
|
||||
|
||||
# make any changes to MySQL installation
|
||||
|
||||
EXPOSE 3306
|
@ -0,0 +1,5 @@
|
||||
FROM wordpress:5.9-apache
|
||||
|
||||
#COPY files , plugins, install extra stuff
|
||||
|
||||
EXPOSE 80
|
42
kubernetes/tutorials/basics/yaml/deploy.yaml
Normal file
42
kubernetes/tutorials/basics/yaml/deploy.yaml
Normal file
@ -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: aimvector/wordpress-example
|
||||
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_NAME
|
18
kubernetes/tutorials/basics/yaml/ingress.yaml
Normal file
18
kubernetes/tutorials/basics/yaml/ingress.yaml
Normal file
@ -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
|
14
kubernetes/tutorials/basics/yaml/service.yaml
Normal file
14
kubernetes/tutorials/basics/yaml/service.yaml
Normal file
@ -0,0 +1,14 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wordpress
|
||||
labels:
|
||||
app: wordpress
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
name: wordpress
|
||||
targetPort: 80
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: wordpress
|
69
kubernetes/tutorials/basics/yaml/statefulset.yaml
Normal file
69
kubernetes/tutorials/basics/yaml/statefulset.yaml
Normal file
@ -0,0 +1,69 @@
|
||||
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: aimvector/mysql-example
|
||||
ports:
|
||||
- containerPort: 3306
|
||||
name: db
|
||||
env:
|
||||
- name: MYSQL_DATABASE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mysql
|
||||
key: MYSQL_DATABASE
|
||||
- name: MYSQL_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mysql
|
||||
key: MYSQL_USER
|
||||
- name: MYSQL_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mysql
|
||||
key: MYSQL_PASSWORD
|
||||
- name: MYSQL_RANDOM_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: mysql
|
||||
key: MYSQL_RANDOM_ROOT_PASSWORD
|
||||
volumeMounts:
|
||||
- name: db
|
||||
mountPath: /var/lib/mysql
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: db
|
||||
spec:
|
||||
accessModes: [ "ReadWriteOnce" ]
|
||||
storageClassName: "standard"
|
||||
resources:
|
||||
requests:
|
||||
storage: 500Mi
|
Loading…
x
Reference in New Issue
Block a user