Skip to content

Commit

Permalink
learn k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
sonthh committed Dec 24, 2024
1 parent 246a215 commit e41db34
Show file tree
Hide file tree
Showing 30 changed files with 147 additions and 101 deletions.
1 change: 1 addition & 0 deletions 03-installation-and-setup/kind-bind-mount-1/test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
XXXX
1 change: 1 addition & 0 deletions 03-installation-and-setup/kind-bind-mount-2/test.xx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
XXXX
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ spec:
spec:
containers:
- name: nginx
image: nginx:1.26.0
# Change image tag then ReplicaSet will create new Pods
image: nginx:1.25.0
4 changes: 4 additions & 0 deletions 04-built-in-resource-types/Deployment/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ tasks:
desc: "Roll the pods in one of the deployments"
cmds:
- kubectl rollout restart deployment nginx-better
# Switch to previous ReplicaSet

- watch "kubectl get pods"

# kubectl rollout undo deployment nginx-better

05-delete-namespace:
desc: "Delete the namespace to clean up"
cmds:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ spec:
pathType: ImplementationSpecific
backend:
service:
name: nginx-clusterip
name: nginx-nodeport
port:
number: 80
# kubectl run curl-pod -it --rm --image=curlimages/curl --command -- sh
# curl -H "Host: ingress-example-nginx.com" <node_ip>:<node_port>
# -H to specify the host header
# <node_ip>: is the IP of the node where the Ingress controller is running
# <node_port>: is the NodePort of the Ingress controller
15 changes: 15 additions & 0 deletions 04-built-in-resource-types/Service/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ tasks:
- cmd: gum style "🚨 Deleting the namespace recursively deletes the resources inside of it! 🚨 "
silent: true
- kubectl delete -f Namespace.yaml
# Debug shell on a node => It create a debug pod on the node
# kubectl debug node/kind-worker2 -it --image=ubuntu

# Debug shell on a pod => It create a debug pod on the same node
# kubectl run curl-pod -it --rm --image=curlimages/curl --command -- sh
# curl <pod_ip>:<pod_port>
# curl <service_ip or service_name>:<service_port>
# eg: curl nginx-clusterip
# node_port defined in the service
# eg: curl <node_ip>:<node_port>

# kubectl run curl-pod -it --rm -n default --image=curlimages/curl --command -- sh
# outside namespace
# curl <service_name>.<namespace>.svc.cluster.local
# eg: curl nginx-clusterip.04--service.svc.cluster.local
1 change: 1 addition & 0 deletions 05-helm/postgresql/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tasks:
silent: true
- helm registry login registry-1.docker.io
desc: Login to OCI registry
# sonthh98/<docker-hub_password>

05-list-registry:
cmds:
Expand Down
2 changes: 1 addition & 1 deletion 06-demo-application/api-golang/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"

vars:
DATABASE_URL: "postgres://postgres:foobarbaz@localhost:5432/postgres"
IMAGE_REPO: sidpalas/devops-directive-docker-course-api-golang
IMAGE_REPO: sonthh98/devops-directive-docker-course-api-golang
IMAGE_TAG: foobarbaz

tasks:
Expand Down
4 changes: 2 additions & 2 deletions 06-demo-application/api-node/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ version: "3"

vars:
DATABASE_URL: "postgres://postgres:foobarbaz@localhost:5432/postgres"
IMAGE_REPO: sidpalas/devops-directive-docker-course-api-node
IMAGE_REPO: sonthh98/devops-directive-docker-course-api-node
IMAGE_TAG: foobarbaz

tasks:
build-container-image:
desc: Build container image
cmds:
- docker build -t {{.IMAGE_REPO}}{{.IMAGE_TAG}} .
- docker build -t {{.IMAGE_REPO}}:{{.IMAGE_TAG}} .

build-container-image-multi-arch:
desc: Build multi-arch container image
Expand Down
2 changes: 1 addition & 1 deletion 06-demo-application/client-react/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"

vars:
IMAGE_REPO: sidpalas/devops-directive-docker-course-client-react-nginx
IMAGE_REPO: sonthh98/devops-directive-docker-course-client-react-nginx
IMAGE_TAG: foobarbaz

tasks:
Expand Down
2 changes: 1 addition & 1 deletion 06-demo-application/load-generator-python/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"

vars:
IMAGE_REPO: sidpalas/devops-directive-kubernetes-course-load-generator-python
IMAGE_REPO: sonthh98/devops-directive-kubernetes-course-load-generator-python
IMAGE_TAG: foobarbaz

tasks:
Expand Down
2 changes: 1 addition & 1 deletion 06-demo-application/postgresql/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"

vars:
IMAGE_REPO: sidpalas/devops-directive-kubernetes-course-db-migrator
IMAGE_REPO: sonthh98/devops-directive-kubernetes-course-db-migrator
IMAGE_TAG: foobarbaz

tasks:
Expand Down
2 changes: 1 addition & 1 deletion 07-deploying-demo-application/api-golang/Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: api-golang
image: sidpalas/devops-directive-docker-course-api-golang:foobarbaz
image: sonthh98/devops-directive-docker-course-api-golang:foobarbaz
env:
- name: PORT
value: "8000"
Expand Down
36 changes: 18 additions & 18 deletions 07-deploying-demo-application/api-golang/IngressRoute.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: api-golang
namespace: demo-app
spec:
entryPoints:
- web
routes:
- kind: Rule
match: Host(`kubernetes-course.devopsdirective.com`) && PathPrefix(`/api/golang`)
middlewares:
- name: strip-api-prefixes
services:
- kind: Service
name: api-golang
port: 8000
scheme: http
# apiVersion: traefik.containo.us/v1alpha1
# kind: IngressRoute
# metadata:
# name: api-golang
# namespace: demo-app
# spec:
# entryPoints:
# - web
# routes:
# - kind: Rule
# match: Host(`kubernetes-course.devopsdirective.com`) && PathPrefix(`/api/golang`)
# middlewares:
# - name: strip-api-prefixes
# services:
# - kind: Service
# name: api-golang
# port: 8000
# scheme: http
2 changes: 1 addition & 1 deletion 07-deploying-demo-application/api-golang/Secret.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ metadata:
name: api-golang-database-url
namespace: demo-app
stringData:
DATABASE_URL: postgres://postgres:foobarbaz@postgres-postgresql.postgres.svc.cluster.local:5432/postgres
DATABASE_URL: postgres://postgres:foobarbaz@postgres-postgresql.postgresx.svc.cluster.local:5432/postgres
2 changes: 1 addition & 1 deletion 07-deploying-demo-application/api-node/Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: api-node
image: sidpalas/devops-directive-docker-course-api-node:foobarbaz
image: sonthh98/devops-directive-docker-course-api-node:foobarbaz
env:
- name: PORT
value: "3000"
Expand Down
36 changes: 18 additions & 18 deletions 07-deploying-demo-application/api-node/IngressRoute.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: api-node
namespace: demo-app
spec:
entryPoints:
- web
routes:
- kind: Rule
match: Host(`kubernetes-course.devopsdirective.com`) && PathPrefix(`/api/node`)
middlewares:
- name: strip-api-prefixes
services:
- kind: Service
name: api-node
port: 3000
scheme: http
# apiVersion: traefik.containo.us/v1alpha1
# kind: IngressRoute
# metadata:
# name: api-node
# namespace: demo-app
# spec:
# entryPoints:
# - web
# routes:
# - kind: Rule
# match: Host(`kubernetes-course.devopsdirective.com`) && PathPrefix(`/api/node`)
# middlewares:
# - name: strip-api-prefixes
# services:
# - kind: Service
# name: api-node
# port: 3000
# scheme: http
2 changes: 1 addition & 1 deletion 07-deploying-demo-application/api-node/Secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ metadata:
name: api-node-database-url
namespace: demo-app
stringData:
DATABASE_URL: postgres://postgres:foobarbaz@postgres-postgresql.postgres.svc.cluster.local:5432/postgres
DATABASE_URL: postgres://postgres:foobarbaz@postgres-postgresql.postgresx.svc.cluster.local:5432/postgres
19 changes: 18 additions & 1 deletion 07-deploying-demo-application/client-react/ConfigMap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,24 @@ data:
add_header 'Content-Type' 'text/plain';
return 200 "pong";
}
location /api/golang/ {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
rewrite ^/api-golang/(.*) /$1 break;
proxy_pass http://api-golang:8000/;
}
location /api/node/ {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
rewrite ^/api/node/(.*) /$1 break;
proxy_pass http://api-node:3000/;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
Expand Down
2 changes: 1 addition & 1 deletion 07-deploying-demo-application/client-react/Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
app: client-react-nginx
spec:
containers:
- image: sidpalas/devops-directive-docker-course-client-react-nginx:foobarbaz
- image: sonthh98/devops-directive-docker-course-client-react-nginx:foobarbaz
name: client-react-nginx
ports:
- containerPort: 8080
Expand Down
32 changes: 16 additions & 16 deletions 07-deploying-demo-application/client-react/IngressRoute.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: client-react-nginx
namespace: demo-app
spec:
entryPoints:
- web
routes:
- kind: Rule
match: Host(`kubernetes-course.devopsdirective.com`)
services:
- kind: Service
name: client-react-nginx
port: 8080
scheme: http
# apiVersion: traefik.containo.us/v1alpha1
# kind: IngressRoute
# metadata:
# name: client-react-nginx
# namespace: demo-app
# spec:
# entryPoints:
# - web
# routes:
# - kind: Rule
# match: Host(`kubernetes-course.devopsdirective.com`)
# services:
# - kind: Service
# name: client-react-nginx
# port: 8080
# scheme: http
22 changes: 11 additions & 11 deletions 07-deploying-demo-application/common/Middleware.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: strip-api-prefixes
namespace: demo-app
spec:
stripPrefix:
forceSlash: false
prefixes:
- /api/node
- /api/golang
# apiVersion: traefik.containo.us/v1alpha1
# kind: Middleware
# metadata:
# name: strip-api-prefixes
# namespace: demo-app
# spec:
# stripPrefix:
# forceSlash: false
# prefixes:
# - /api/node
# - /api/golang
18 changes: 9 additions & 9 deletions 07-deploying-demo-application/common/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ tasks:
- kubectl apply -f Namespace.yaml
- kubens demo-app

deploy-traefik:
desc: "Deploy Traefik using Helm"
cmds:
- helm repo add traefik https://traefik.github.io/charts
- helm upgrade --install -n traefik --create-namespace traefik traefik/traefik --version 20.8.0
# deploy-traefik:
# desc: "Deploy Traefik using Helm"
# cmds:
# - helm repo add traefik https://traefik.github.io/charts
# - helm upgrade --install -n traefik --create-namespace traefik traefik/traefik --version 20.8.0

apply-traefik-middleware:
desc: "Deploy Traefik middleware"
cmds:
- "kubectl apply -f Middleware.yaml"
# apply-traefik-middleware:
# desc: "Deploy Traefik middleware"
# cmds:
# - "kubectl apply -f Middleware.yaml"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ metadata:
name: load-generator-config
namespace: demo-app
data:
API_URL: http://api-node.demo-app.svc.cluster.local:3000
# API_URL: http://api-golang.demo-app.svc.cluster.local:8080
# API_URL: http://api-node.demo-app.svc.cluster.local:3000
API_URL: http://api-golang.demo-app.svc.cluster.local:8080
DELAY_MS: "100"
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ spec:
spec:
containers:
- name: load-generator
image: sidpalas/devops-directive-kubernetes-course-load-generator-python:foobarbaz
image: sonthh98/devops-directive-kubernetes-course-load-generator-python:foobarbaz
imagePullPolicy: Always
env:
- name: API_URL
value: http://api-node.demo-app.svc.cluster.local:3000
- name: DELAY_MS
value: "500"
# env:
# - name: API_URL
# value: http://api-node.demo-app.svc.cluster.local:3000
# - name: DELAY_MS
# value: "500"
# Could alternatively move these to a configmap
# envFrom:
# - configMapRef:
# name: load-generator-config
envFrom:
- configMapRef:
name: load-generator-config
resources:
limits:
memory: "50Mi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
spec:
containers:
- name: migrate
image: sidpalas/devops-directive-kubernetes-course-db-migrator:foobarbaz
image: sonthh98/devops-directive-kubernetes-course-db-migrator:foobarbaz
args:
- -path=/app/migrations
- -database=$(DATABASE_URL)?sslmode=disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ metadata:
namespace: demo-app
type: Opaque
stringData:
DATABASE_URL: postgres://postgres:[email protected]:5432/postgres
DATABASE_URL: postgres://postgres:[email protected]:5432/postgres
# cat /etc/resolv.conf in Postgres pod to get the cluster DNS suffix
2 changes: 1 addition & 1 deletion 07-deploying-demo-application/postgresql/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tasks:
- helm repo add bitnami https://charts.bitnami.com/bitnami
- |
helm upgrade --install \
-n postgres \
-n postgresx \
postgres bitnami/postgresql \
--set auth.postgresPassword=foobarbaz \
--version 15.3.2 \
Expand Down
Loading

0 comments on commit e41db34

Please sign in to comment.