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