您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
43、存储 Volume(3)
发布时间:2023-01-02 14:41:03编辑:雪饮阅读()
Step1
首先同样是做下清理工作
[root@k8s-master01 ~]# kubectl delete pod --all
pod "test-pd1" deleted
然后我们需要到node01和node02上分别建立我们要挂载到节点上面的目录
[root@k8s-node01 ~]# mkdir /data
[root@k8s-node02 ~]# mkdir /data
然后在node01里面看看目录权限,应该是为了保证可读写权限。
实际上我是这样认为的,应该是随便node01还是node02上面看都可以,毕竟节点都是属于集群的,他们的要求肯定都是一样的,环境什么基本都是相同的,不同的话,集群多少就算是不完美了。
由于这里看到docker是以root权限运行的
[root@k8s-node01 ~]# ps uax | grep docker
root 1109 0.6 2.4 1348208 99404 ? Ssl 13:43 0:03 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 8623 0.0 0.0 112836 2388 pts/0 S+ 13:53 0:00 grep --color=auto docker
所以权限肯定没有问题咯
关于ps的aux参数
a 显示终端上的所有进程,包括其他用户的进程。
u 指定用户的所有进程
x 显示没有控制终端的进程。
不过滤时候的字段列表完全展示如
[root@k8s-node01 ~]# ps uax
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.1 0.1 43724 5488 ? Ss 13:41 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S 13:41 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 13:41 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< 13:41 0:00 [rcu_par_gp]
root 6 0.0 0.0 0 0 ? I< 13:41 0:00 [kworker/0:0H-kb]
root 7 0.0 0.0 0 0 ? I 13:41 0:00 [kworker/u256:0-]
Step2
然后创建以hostpath方式挂载的pod
[root@k8s-master01 volume]# cat pod3.yaml
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: wangyanglinux/myapp:v2
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
hostPath:
path: /data
type: Directory
这里是挂载于pod内部的/test-pod目录,而对应节点的实际路径为/data
[root@k8s-master01 volume]# kubectl create -f pod3.yaml
pod/test-pd created
[root@k8s-master01 volume]# kubectl get pod
NAME READY STATUS RESTARTS AGE
test-pd 1/1 Running 0 72s
由于只是一个pod而已,并非deployment,所以我们看看部署的所在节点
[root@k8s-master01 volume]# kubectl describe pod test-pd
Name: test-pd
Namespace: default
Priority: 0
Node: k8s-node02/192.168.66.21
Start Time: Mon, 02 Jan 2023 14:29:51 +0800
Labels: <none>
Annotations: <none>
Status: Running
IP: 10.224.2.178
Containers:
test-container:
Container ID: docker://55a7d6b67c97b07f42e85253e8f1503850d97910dd1a05545dc4a35c057a69be
Image: wangyanglinux/myapp:v2
Image ID: docker-pullable://wangyanglinux/myapp@sha256:85a2b81a62f09a414ea33b74fb8aa686ed9b168294b26b4c819df0be0712d358
Port: <none>
Host Port: <none>
State: Running
Started: Mon, 02 Jan 2023 14:29:52 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/test-pd from test-volume (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-d8kh2 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
test-volume:
Type: HostPath (bare host directory volume)
Path: /data
HostPathType: Directory
default-token-d8kh2:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-d8kh2
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m49s default-scheduler Successfully assigned default/test-pd to k8s-node02
Normal Pulled 2m48s kubelet, k8s-node02 Container image "wangyanglinux/myapp:v2" already present on machine
Normal Created 2m48s kubelet, k8s-node02 Created container test-container
Normal Started 2m48s kubelet, k8s-node02 Started container test-container
可以看到是运行在node02上的
那么我在pod上面写入到这个pod挂载点上面一个文件中
[root@k8s-master01 volume]# kubectl exec test-pd -it -- /bin/sh
/ # ls /test-pd
/ # date > /test-pd/index.html
/ # cat /test-pd/index.html
Mon Jan 2 06:36:03 UTC 2023
然后在node01节点上查看这个文件
[root@k8s-node01 ~]# ls /data
显然是没有的,但是在node02上面就能看到了,并且在node02节点上追加新的内容
[root@k8s-node02 ~]# ls /data
index.html
[root@k8s-node02 ~]# cat /data/index.html
Mon Jan 2 06:36:03 UTC 2023
[root@k8s-node02 ~]# date >> /data/index.html
[root@k8s-node02 ~]# cat /data/index.html
Mon Jan 2 06:36:03 UTC 2023
2023年 01月 02日 星期一 14:37:54 CST
哈哈,这里可以看到节点2当时是中文的语言于安装centos时候吧,master当时应该是没有设置中文语言,看来集群有那么不同步语言的一小点瑕疵,一小点不完美哈。
那么从master上就可以看到pod上面这个挂载点/test-pd中刚才新增的这个文件的内容也同步被追加了内容
/ # cat /test-pd/index.html
Mon Jan 2 06:36:03 UTC 2023
2023年 01月 02日 星期一 14:37:54 CST
关键字词:存储,Volume
上一篇:42.存储 Volume(2)
下一篇:45、存储 PV-PVC(2)