k8s学习笔记二之使用gcloud了解volume
1
2
3
4
5
|
gcloud config set compute/zone asia-northeast1-b
gcloud config set project my-k8s-codelab-225201
gcloud container clusters create k8s-101
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
cat << EOF > pod-nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
EOF
|
1
2
3
|
kubectl create -f pod-nginx.yaml
kubectl get pods
|
Pod 的 IP 都是外部不可见的。最便捷的测试 Pod 是否工作的方法是创建一个 busybox pod 并且在上面远程运行命令。
1
2
3
4
5
6
|
kubectl run busybox --image=busybox --restart=Never --tty -i --generator=run-pod/v1 --env "POD_IP=$(kubectl get pod nginx -o go-template='{{.status.podIP}}')"
wget -qO- http://$POD_IP
exit
kubectl delete pod busybox
kubectl delete pod nginx
|
valume
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
cat << EOF > pod-redis.yaml
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis
volumeMounts:
- name: redis-persistent-storage
mountPath: /data/redis
volumes:
- name: redis-persistent-storage
emptyDir: {}
EOF
|
EmptyDir
: 在 node 上创建一个和 pod 同生命周期的文件夹,容器出错或重启都会使用这个文件夹。
HostPath
: 挂在文件到一个系统上已存目录上 (例如 /var/logs
多容器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
cat <<EOF > pod-multi-web.yaml
apiVersion: v1
kind: Pod
metadata:
name: multi-web
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: www-data
mountPath: /srv/wwww
readOnly: true
- name: git-monitor
image: kubernetes/git-monitor
env:
- name: GIT_REPO
value: https://github.com/wx11055/wx11055.github.io
volumeMounts:
- mountPath: /data
name: www-data
volumes:
- name: www-data
emptyDir: {}
EOF
|