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,69 @@
# Ch12 lab
## Setup
Deploy the namespaces & Services:
```
kubectl apply -f lab/namespaces.yaml -f lab/services.yaml
```
Find out how many cores your node has available:
```
kubectl get nodes -o jsonpath='{.items[].status.allocatable.cpu}'
```
> Quotas should allocate 50% for UAT, 25% for test and 25% for dev
## Sample Solution
My node has 8 CPU cores, so my [quotas.yaml](./solution/quotas.yaml) is set with 4 cores for UAT and 2 each for dev and test.
Set the quotas:
```
kubectl apply -f lab/solution/quotas.yaml
```
My Pi app is set in [web.yaml](./solution/web.yaml) to use 0.5 cores, so I can run at least four replicas in every environment.
Deploy to each namespace:
```
kubectl apply -f lab/solution/web.yaml -n pi-dev
kubectl apply -f lab/solution/web.yaml -n pi-test
kubectl apply -f lab/solution/web.yaml -n pi-uat
```
You should find all ReplicaSets are running at desired capacity:
```
kubectl get rs -l app=pi-web --all-namespaces
```
UAT has enough quota to run 8 replicas on my node:
```
kubectl scale deploy/pi-web --replicas 8 -n pi-uat
```
... except that it doesn't:
```
kubectl get rs -l app=pi-web -n pi-uat\
# returns 6 Pods running out of 8 desired
```
> You can't use 100% of the node's CPU because Kubernetes system components allocate CPU themselves.
## Teardown
Remove the namespaces and that removes everything:
```
kubectl delete ns -l kiamol=ch12-lab
```

View File

@@ -0,0 +1,20 @@
apiVersion: v1
kind: Namespace
metadata:
name: pi-dev
labels:
kiamol: ch12-lab
---
apiVersion: v1
kind: Namespace
metadata:
name: pi-test
labels:
kiamol: ch12-lab
---
apiVersion: v1
kind: Namespace
metadata:
name: pi-uat
labels:
kiamol: ch12-lab

View File

@@ -0,0 +1,44 @@
apiVersion: v1
kind: Service
metadata:
name: pi-web
namespace: pi-dev
labels:
kiamol: ch12-lab
spec:
ports:
- port: 8012
targetPort: http
selector:
app: pi-web
type: LoadBalancer
---
apiVersion: v1
kind: Service
metadata:
name: pi-web
namespace: pi-test
labels:
kiamol: ch12-lab
spec:
ports:
- port: 8013
targetPort: http
selector:
app: pi-web
type: LoadBalancer
---
apiVersion: v1
kind: Service
metadata:
name: pi-web
namespace: pi-uat
labels:
kiamol: ch12-lab
spec:
ports:
- port: 8014
targetPort: http
selector:
app: pi-web
type: LoadBalancer

View File

@@ -0,0 +1,32 @@
apiVersion: v1
kind: ResourceQuota
metadata:
name: cpu-quota
namespace: pi-dev
labels:
kiamol: ch12-lab
spec:
hard:
limits.cpu: 2
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: cpu-quota
namespace: pi-test
labels:
kiamol: ch12-lab
spec:
hard:
limits.cpu: 2
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: cpu-quota
namespace: pi-uat
labels:
kiamol: ch12-lab
spec:
hard:
limits.cpu: 4

View File

@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pi-web
labels:
kiamol: ch12-lab
spec:
replicas: 4
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
resources:
limits:
cpu: 500m

View File

@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pi-web
labels:
kiamol: ch12-lab
spec:
replicas: 4
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
# TODO - add resource limits