新增learn-kubernetes(https://github.com/yyong-brs/learn-kubernetes)相关文件
This commit is contained in:
69
learn/learn-kubernetes-master/kiamol/ch12/lab/README.md
Normal file
69
learn/learn-kubernetes-master/kiamol/ch12/lab/README.md
Normal 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
|
||||
```
|
||||
@@ -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
|
||||
44
learn/learn-kubernetes-master/kiamol/ch12/lab/services.yaml
Normal file
44
learn/learn-kubernetes-master/kiamol/ch12/lab/services.yaml
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
24
learn/learn-kubernetes-master/kiamol/ch12/lab/web.yaml
Normal file
24
learn/learn-kubernetes-master/kiamol/ch12/lab/web.yaml
Normal 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
|
||||
Reference in New Issue
Block a user