新增learn-kubernetes(https://github.com/yyong-brs/learn-kubernetes)相关文件
This commit is contained in:
56
learn/learn-kubernetes-master/kiamol/ch08/lab/README.md
Normal file
56
learn/learn-kubernetes-master/kiamol/ch08/lab/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Ch08 lab
|
||||
|
||||
Run the app:
|
||||
|
||||
```
|
||||
kubectl apply -f lab/nginx/
|
||||
```
|
||||
|
||||
Get the URL and browse:
|
||||
|
||||
```
|
||||
kubectl get svc nginx -o jsonpath='http://{.status.loadBalancer.ingress[0].*}:8088'
|
||||
```
|
||||
|
||||
> It works, but its just a single Pod writing logs to an EmptyDir.
|
||||
|
||||
## Sample Solution
|
||||
|
||||
My [StatefulSet](solution/nginx-statefulset.yaml) runs three Pods, with volume claim templates for storage.
|
||||
|
||||
```
|
||||
kubectl apply -f lab/solution/nginx-statefulset.yaml
|
||||
```
|
||||
|
||||
> Make lots of calls to the web app
|
||||
|
||||
I used this in Powershell:
|
||||
|
||||
```
|
||||
for($i = 0; $i -lt 100; $i++) { curl http://localhost:8088 | Out-Null }
|
||||
```
|
||||
|
||||
Then the [Job](solution/disk-calc-job.yaml) is configured to mount all of the PVCs used in the StatefulSet Pods.
|
||||
|
||||
```
|
||||
kubectl apply -f lab/solution/disk-calc-job.yaml
|
||||
```
|
||||
|
||||
When I check the logs I see this:
|
||||
|
||||
```
|
||||
PS>kubectl logs -l job-name=disk-calc
|
||||
32.0K /nginx0/access.log
|
||||
24.0K /nginx1/access.log
|
||||
40.0K /nginx2/access.log
|
||||
```
|
||||
|
||||
## Teardown
|
||||
|
||||
Delete the lab resources by their labels:
|
||||
|
||||
```
|
||||
kubectl delete all -l kiamol=ch08-lab
|
||||
|
||||
kubectl delete pvc -l kiamol=ch08-lab
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
apiVersion: v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
kiamol: ch08-lab
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- image: kiamol/ch03-sleep
|
||||
name: calc
|
||||
command: ['sh', '-c', 'du -h /nginx1/access.log /nginx2/access.log /nginx3/access.log']
|
||||
ports:
|
||||
- containerPort: 80
|
||||
volumeMounts:
|
||||
- name: nginx1
|
||||
mountPath: /nginx1/
|
||||
- name: nginx2
|
||||
mountPath: /nginx2/
|
||||
- name: nginx3
|
||||
mountPath: /nginx3/
|
||||
# volumes:
|
||||
# ?
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
kiamol: ch08-lab
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
- port: 8088
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -0,0 +1,19 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
kiamol: ch08-lab
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.17-alpine
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
volumeMounts:
|
||||
- name: logs
|
||||
mountPath: /var/log/nginx/
|
||||
volumes:
|
||||
- name: logs
|
||||
emptyDir: {}
|
||||
@@ -0,0 +1,33 @@
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: disk-calc
|
||||
labels:
|
||||
kiamol: ch08-lab
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- image: kiamol/ch03-sleep
|
||||
name: calc
|
||||
command: ['sh', '-c', 'du -h /nginx0/access.log /nginx1/access.log /nginx2/access.log']
|
||||
ports:
|
||||
- containerPort: 80
|
||||
volumeMounts:
|
||||
- name: nginx0
|
||||
mountPath: /nginx0/
|
||||
- name: nginx1
|
||||
mountPath: /nginx1/
|
||||
- name: nginx2
|
||||
mountPath: /nginx2/
|
||||
volumes:
|
||||
- name: nginx0
|
||||
persistentVolumeClaim:
|
||||
claimName: logs-nginx-stateful-0
|
||||
- name: nginx1
|
||||
persistentVolumeClaim:
|
||||
claimName: logs-nginx-stateful-1
|
||||
- name: nginx2
|
||||
persistentVolumeClaim:
|
||||
claimName: logs-nginx-stateful-2
|
||||
@@ -0,0 +1,50 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
kiamol: ch08-lab
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
- port: 8088
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: nginx-stateful
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: nginx-stateful
|
||||
labels:
|
||||
kiamol: ch08-lab
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx-stateful
|
||||
serviceName: nginx-stateful
|
||||
replicas: 3
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx-stateful
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.17-alpine
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
volumeMounts:
|
||||
- name: logs
|
||||
mountPath: /var/log/nginx/
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: logs
|
||||
labels:
|
||||
kiamol: ch08-lab
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Mi
|
||||
Reference in New Issue
Block a user