This commit is contained in:
2024-02-20 17:15:27 +08:00
committed by huty
parent 6706e1a633
commit 34158042ad
1529 changed files with 177765 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
# Ch06 lab
Run the app:
```
kubectl apply -f lab/numbers/
```
Get the URL to browse to:
```
kubectl get svc numbers-web -o jsonpath='http://{.status.loadBalancer.ingress[0].*}:8086'
```
> Browse and try to get a random number, the app fails.
## Sample Solution
Add the RNG label to a node:
```
kubectl label node $(kubectl get nodes -o jsonpath='{.items[0].metadata.name}') rng=hw
```
Deploy the new resources - a [Deployment](solution/web-deployment.yaml) for the web app and a [DaemonSet](solution/api-daemonset.yaml) for the API:
```
kubectl apply -f lab/solution/
```
> Refresh the browser and confirm you can get a random number.
Delete the old resources by their labels:
```
kubectl get all -l kiamol=ch06-lab
kubectl delete all -l kiamol=ch06-lab
```

View File

@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: numbers-api
labels:
kiamol: ch06-lab
spec:
ports:
- port: 80
selector:
app: numbers-api
type: ClusterIP

View File

@@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
name: numbers-api
labels:
kiamol: ch06-lab
spec:
containers:
- name: api
image: kiamol/ch03-numbers-api

View File

@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: numbers-web
labels:
kiamol: ch06-lab
spec:
ports:
- port: 8086
targetPort: 80
selector:
app: numbers-web
type: LoadBalancer

View File

@@ -0,0 +1,18 @@
apiVersion: v1
kind: ReplicationController
metadata:
name: numbers-web
labels:
kiamol: ch06-lab
spec:
replicas: 2
selector:
app: numbers-web
template:
metadata:
labels:
app: numbers-web
spec:
containers:
- name: web
image: kiamol/ch03-numbers-web

View File

@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: numbers-api
labels:
kiamol: ch06-lab
spec:
selector:
matchLabels:
app: numbers-api
template:
metadata:
labels:
app: numbers-api
spec:
containers:
- name: api
image: kiamol/ch03-numbers-api
nodeSelector:
rng: hw

View File

@@ -0,0 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: numbers-web
labels:
kiamol: ch06-lab
spec:
replicas: 2
selector:
matchLabels:
app: numbers-web
template:
metadata:
labels:
app: numbers-web
spec:
containers:
- name: web
image: kiamol/ch03-numbers-web

View File

@@ -0,0 +1,37 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: pi-proxy
labels:
kiamol: ch06
spec:
selector:
matchLabels:
app: pi-proxy
template:
metadata:
labels:
app: pi-proxy
spec:
containers:
- image: nginx:1.17-alpine
name: nginx
ports:
- containerPort: 80
name: http
volumeMounts:
- name: config
mountPath: "/etc/nginx/"
readOnly: true
- name: cache-volume
mountPath: /data/nginx/cache
volumes:
- name: config
configMap:
name: pi-proxy-configmap
- name: cache-volume
hostPath:
path: /volumes/nginx-cache
type: DirectoryOrCreate
nodeSelector:
kiamol: ch06

View File

@@ -0,0 +1,35 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: pi-proxy
labels:
kiamol: ch06
spec:
selector:
matchLabels:
app: pi-proxy
template:
metadata:
labels:
app: pi-proxy
spec:
containers:
- image: nginx:1.17-alpine
name: nginx
ports:
- containerPort: 80
name: http
volumeMounts:
- name: config
mountPath: "/etc/nginx/"
readOnly: true
- name: cache-volume
mountPath: /data/nginx/cache
volumes:
- name: config
configMap:
name: pi-proxy-configmap
- name: cache-volume
hostPath:
path: /volumes/nginx-cache
type: DirectoryOrCreate

View File

@@ -0,0 +1,45 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: pi-proxy-configmap
labels:
kiamol: ch06
data:
nginx.conf: |-
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
gzip on;
gzip_proxied any;
map $sent_http_content_type $expires {
default off;
~image/ 6M;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
proxy_pass http://pi-web;
proxy_set_header Host $host;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
add_header X-Cache $upstream_cache_status;
add_header X-Host $hostname;
}
}
}

View File

@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: pi-proxy
labels:
kiamol: ch06
spec:
ports:
- port: 8080
targetPort: 80
selector:
app: pi-proxy
type: LoadBalancer

View File

@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pi-proxy
labels:
kiamol: ch06
spec:
replicas: 2
selector:
matchLabels:
app: pi-proxy
template:
metadata:
labels:
app: pi-proxy
spec:
containers:
- image: nginx:1.17-alpine
name: nginx
ports:
- containerPort: 80
name: http
volumeMounts:
- name: config
mountPath: "/etc/nginx/"
readOnly: true
- name: cache-volume
mountPath: /data/nginx/cache
volumes:
- name: config
configMap:
name: pi-proxy-configmap
- name: cache-volume
emptyDir: {}

View File

@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pi-proxy
labels:
kiamol: ch06
spec:
replicas: 3
selector:
matchLabels:
app: pi-proxy
template:
metadata:
labels:
app: pi-proxy
spec:
containers:
- image: nginx:1.17-alpine
name: nginx
ports:
- containerPort: 80
name: http
volumeMounts:
- name: config
mountPath: "/etc/nginx/"
readOnly: true
- name: cache-volume
mountPath: /data/nginx/cache
volumes:
- name: config
configMap:
name: pi-proxy-configmap
- name: cache-volume
hostPath:
path: /volumes/nginx-cache
type: DirectoryOrCreate

View File

@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pi-web
labels:
kiamol: ch06
spec:
replicas: 3
selector:
matchLabels:
app: pi-web
template:
metadata:
labels:
app: pi-web
spec:
containers:
- image: kiamol/ch05-pi
command: ["dotnet", "Pi.Web.dll", "-m", "web"]
name: web
ports:
- containerPort: 80
name: http
env:
- name: Logging__LogLevel__Default
value: Debug

View File

@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pi-web
labels:
kiamol: ch06
spec:
replicas: 3
selector:
matchLabels:
app: pi-web
template:
metadata:
labels:
app: pi-web
spec:
containers:
- image: kiamol/ch05-pi
command: ["dotnet", "Pi.Web.dll", "-m", "web"]
name: web
ports:
- containerPort: 80
name: http

View File

@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: pi-web
labels:
kiamol: ch06
spec:
ports:
- port: 80
name: http
selector:
app: pi-web
type: ClusterIP

View File

@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pi-web
labels:
kiamol: ch06
spec:
replicas: 2
selector:
matchLabels:
app: pi-web
template:
metadata:
labels:
app: pi-web
spec:
containers:
- image: kiamol/ch05-pi
command: ["dotnet", "Pi.Web.dll", "-m", "web"]
name: web
ports:
- containerPort: 80
name: http

View File

@@ -0,0 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: sleep
labels:
kiamol: ch06
spec:
selector:
matchLabels:
app: sleep
template:
metadata:
labels:
app: sleep
spec:
containers:
- name: sleep
image: kiamol/ch03-sleep

View File

@@ -0,0 +1,2 @@
Moved to [ch08](../../ch08/todo-list).

View File

@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: whoami-web
labels:
kiamol: ch06
spec:
replicas: 3
selector:
matchLabels:
app: whoami-web
template:
metadata:
labels:
app: whoami-web
spec:
containers:
- image: kiamol/ch02-whoami
name: web
ports:
- containerPort: 80
name: http

View File

@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: whoami-web
labels:
kiamol: ch06
spec:
ports:
- port: 8088
targetPort: 80
selector:
app: whoami-web
type: LoadBalancer

View File

@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: whoami-web
labels:
kiamol: ch06
spec:
replicas: 1
selector:
matchLabels:
app: whoami-web
template:
metadata:
labels:
app: whoami-web
spec:
containers:
- image: kiamol/ch02-whoami
name: web
ports:
- containerPort: 80
name: http