mirror of
https://github.com/acedemand/kubernetes-essentials.git
synced 2021-08-24 18:29:57 +03:00
storage introduction
This commit is contained in:
21
08-storage/intro/01-2-emptydir-pod.yaml
Normal file
21
08-storage/intro/01-2-emptydir-pod.yaml
Normal file
@@ -0,0 +1,21 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-pd
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.7.9
|
||||
name: test-container
|
||||
volumeMounts:
|
||||
- mountPath: /usr/share/nginx/html
|
||||
name: cache-volume
|
||||
initContainers:
|
||||
- name: git-code-downlaod
|
||||
image: alpine/git
|
||||
command: ['sh', '-c', 'git clone https://github.com/wlsf82/helloworld.git; mv * /cache ']
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
20
08-storage/intro/01-3-emptydir-pod.yaml
Normal file
20
08-storage/intro/01-3-emptydir-pod.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-pd
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.7.9
|
||||
name: test-container
|
||||
volumeMounts:
|
||||
- mountPath: /usr/share/nginx/html
|
||||
name: cache-volume
|
||||
- name: git-code-downlaod
|
||||
image: alpine/git
|
||||
command: ['sh', '-c', 'while true; do rm -rdf /cache/*; git clone https://github.com/wlsf82/helloworld.git; mv -f helloworld/ /cache; sleep 30; done; ']
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
27
08-storage/intro/01-4-emptydir-pod.yaml
Normal file
27
08-storage/intro/01-4-emptydir-pod.yaml
Normal file
@@ -0,0 +1,27 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-pd
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.7.9
|
||||
name: test-container
|
||||
volumeMounts:
|
||||
- mountPath: /usr/share/nginx/html
|
||||
name: cache-volume
|
||||
initContainers:
|
||||
- name: template-changer
|
||||
image: alpine/git
|
||||
command: ['sh', '-c', 'cp /conf/* /cache; chmod +x /cache/*']
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
- mountPath: /conf
|
||||
name: conf
|
||||
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
- name: conf
|
||||
configMap:
|
||||
name: mysql-conn
|
||||
14
08-storage/intro/01-emptydir-pod.yaml
Normal file
14
08-storage/intro/01-emptydir-pod.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-pd
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.7.9
|
||||
name: test-container
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
16
08-storage/intro/02-emptydir-memory.yaml
Normal file
16
08-storage/intro/02-emptydir-memory.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-pd
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.7.9
|
||||
name: test-container
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir:
|
||||
medium: Memory
|
||||
sizeLimit: "1Gi"
|
||||
29
08-storage/intro/04-downwardapi.yaml
Normal file
29
08-storage/intro/04-downwardapi.yaml
Normal file
@@ -0,0 +1,29 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: nginx-pd
|
||||
labels:
|
||||
zone: us-est-coast
|
||||
cluster: test-cluster1
|
||||
rack: rack-22
|
||||
annotations:
|
||||
build: two
|
||||
builder: john-doe
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx-pd
|
||||
image: nginx:1.7.9
|
||||
volumeMounts:
|
||||
- name: podinfo
|
||||
mountPath: /etc/podinfo
|
||||
readOnly: false
|
||||
volumes:
|
||||
- name: podinfo
|
||||
downwardAPI:
|
||||
items:
|
||||
- path: "labels"
|
||||
fieldRef:
|
||||
fieldPath: metadata.labels
|
||||
- path: "annotations"
|
||||
fieldRef:
|
||||
fieldPath: metadata.annotations
|
||||
44
08-storage/intro/Readme.md
Normal file
44
08-storage/intro/Readme.md
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
### EmptyDir
|
||||
```bash
|
||||
vim 01-2-emptydir-pod.yaml
|
||||
kubectl apply -f 01-2-emptydir-pod.yaml
|
||||
kubectl port-forward test-pd 8080:80
|
||||
curl -XGET http://localhost:8080/helloworld/helloworld.html
|
||||
kubectl delete -f 01-2-emptydir-pod.yaml
|
||||
```
|
||||
|
||||
### Bad Practice
|
||||
```bash
|
||||
kubectl apply -f 01-3-emptydir-pod.yaml
|
||||
kubectl port-forward test-pd 8080:80
|
||||
curl -XGET http://localhost:8080/helloworld/helloworld.html
|
||||
kubectl delete -f 01-3-emptydir-pod.yaml
|
||||
```
|
||||
|
||||
### Secret Volume
|
||||
```bash
|
||||
echo mysql://root:topsecretpassword@remote_mysql:3306/acedemand > mysql.conn
|
||||
kubectl create secret generic mysqlconnection --from-file=mysql.conn
|
||||
kubectl apply -f 03-secretdir.yaml
|
||||
kubectl exec -it test-pd -- /bin/sh
|
||||
ls /secret
|
||||
cat /secret/mysql.conn
|
||||
```
|
||||
|
||||
### configmap readonly
|
||||
```bash
|
||||
kubectl create configmap mysql-conn --from-file mysql.conn
|
||||
kubectl apply -f 01-4-emptydir-pod.yaml
|
||||
kubectl exec -it test-pd -- /bin/sh
|
||||
cd /usr/share/nginx/html
|
||||
ls -lart
|
||||
# find executable rights
|
||||
kubectl delete configmap mysql-conn
|
||||
kubectl delete -f 01-4-emptydir-pod.yaml
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1
08-storage/intro/mysql.conn
Normal file
1
08-storage/intro/mysql.conn
Normal file
@@ -0,0 +1 @@
|
||||
mysql://root:topsecretpassword@remote_mysql:3306/acedemand
|
||||
Reference in New Issue
Block a user