k8s之持久卷NFS
一、简介
NFS网络存储卷,Kubernetes原生支持NFS作为Kubernetes的持久存储卷之一。NFS可以实现Pod的跨界点的数据持久性。
- 首先需要创建一个nfs 服务器,作为存储服务器;
- 将nfs服务器上导出 (export)的文件系统用作存储卷;
- nfs是文件系统级共享服务,它支持多路挂载请求,可由多个Pod对象同时用作存储卷后端;
二、准备NFS服务器
1、安装NFS-server
root@k8s-node03:~# apt search ^nfs-ker
Sorting... Done
Full Text Search... Done
nfs-kernel-server/jammy-updates 1:2.6.1-1ubuntu1.2 amd64
support for NFS kernel server
root@k8s-node03:~# apt install nfs-kernel-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
nfs-kernel-server
0 upgraded, 1 newly installed, 0 to remove and 65 not upgraded.
Need to get 140 kB of archives.
After this operation, 526 kB of additional disk space will be used.
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu jammy-updates/main amd64 nfs-kernel-server amd64 1:2.6.1-1ubuntu1.2 [140 kB]
Fetched 140 kB in 2s (72.6 kB/s)
Selecting previously unselected package nfs-kernel-server.
(Reading database ... 94308 files and directories currently installed.)
Preparing to unpack .../nfs-kernel-server_1%3a2.6.1-1ubuntu1.2_amd64.deb ...
Unpacking nfs-kernel-server (1:2.6.1-1ubuntu1.2) ...
Setting up nfs-kernel-server (1:2.6.1-1ubuntu1.2) ...
Created symlink /etc/systemd/system/nfs-client.target.wants/nfs-blkmap.service → /lib/systemd/system/nfs-blkmap.service.
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /lib/systemd/system/nfs-server.service.
nfs-mountd.service is a disabled or a static unit, not starting it.
nfsdcld.service is a disabled or a static unit, not starting it.
Creating config file /etc/exports with new version
Creating config file /etc/default/nfs-kernel-server with new version
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning candidates...
Scanning linux images...
Restarting services...
Service restarts being deferred:
/etc/needrestart/restart.d/dbus.service
systemctl restart docker.service
systemctl restart getty@tty1.service
systemctl restart networkd-dispatcher.service
systemctl restart systemd-logind.service
systemctl restart unattended-upgrades.service
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
2、准备共享目录
root@k8s-node03:~# mkdir -pv /data/redis
mkdir: created directory '/data'
mkdir: created directory '/data/redis'
root@k8s-node03:~# vi /etc/exports
root@k8s-node03:~# cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/data/redis 192.168.10.0/24(rw,no_root_squash,no_subtree_check)
3、启动NFS服务
root@k8s-node03:~# systemctl restart nfs-server
root@k8s-node03:~# systemctl status nfs-server
● nfs-server.service - NFS server and services
Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2024-01-23 22:14:32 CST; 10s ago
Process: 1595248 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Process: 1595250 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
Main PID: 1595250 (code=exited, status=0/SUCCESS)
CPU: 10ms
Jan 23 22:14:32 k8s-node03 systemd[1]: Starting NFS server and services...
Jan 23 22:14:32 k8s-node03 systemd[1]: Finished NFS server and services.
三、客户端安装NFS工具
1、安装NFS客户端工具
root@k8s-node02:~# apt install nfs-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
nfs-common is already the newest version (1:2.6.1-1ubuntu1.2).
0 upgraded, 0 newly installed, 0 to remove and 65 not upgraded.
root@k8s-node03:~#
2、验证挂载NFS共享目录
root@k8s-node02:~# mount -t nfs 192.168.10.13:/data/redis /mnt/
root@k8s-node02:~# cd /mnt/
root@k8s-node02:/mnt# ls
root@k8s-node02:/mnt# touch test
root@k8s-node02:/mnt# echo 666> test
3、NFS查看已经有数据
root@k8s-node03:~# cat /data/redis/test
666
root@k8s-node03:~#
四、Pod挂载NFS存储卷,验证数据存储的持久性
1、创建Pod并挂载NFS存储卷
root@k8s-master01:~/learning-k8s/examples/volumes# cat pod-with-nfs-vol.yaml
apiVersion: v1
kind: Pod
metadata:
name: redis-nfs-002
spec:
containers:
- name: redis
image: redis:7-alpine
imagePullPolicy: IfNotPresent
volumeMounts:
- name: redisdata
mountPath: /data
volumes:
- name: redisdata
nfs:
server: 192.168.10.13
path: /data/redis
root@k8s-master01:~/learning-k8s/examples/volumes# kubectl apply -f pod-with-nfs-vol.yaml
root@k8s-master01:~/learning-k8s/examples/volumes# kubectl get pod
NAME READY STATUS RESTARTS AGE
redis-nfs-002 1/1 Running 0 19s
2、进入容器创建测试数据
root@k8s-master01:~/learning-k8s/examples/volumes# kubectl exec -it redis-nfs-002 /bin/sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
/data # redis-c
redis-check-aof redis-check-rdb redis-cli
/data # redis-cli
127.0.0.1:6379> SET mykey test
OK
127.0.0.1:6379> BGSAVE
Background saving started
127.0.0.1:6379> EXIT
/data # ls
dump.rdb test
3、删除Pod,验证数据持久性
- 第一次nfs Pod被调度在k8s-node02 节点上。
root@k8s-master01:~/learning-k8s/examples/volumes# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
redis-nfs-002 1/1 Running 0 7m49s 10.244.1.4 k8s-node02 <none> <none>
- 删除Pod,并重新创建,人为调度到k8s-node01节点上
root@k8s-master01:~/learning-k8s/examples/volumes# kubectl delete -f pod-with-nfs-vol.yaml
pod "redis-nfs-002" deleted
root@k8s-master01:~/learning-k8s/examples/volumes# cat pod-with-nfs-vol.yaml
apiVersion: v1
kind: Pod
metadata:
name: redis-nfs-002
spec:
nodeName: k8s-node01
containers:
- name: redis
image: redis:7-alpine
imagePullPolicy: IfNotPresent
volumeMounts:
- name: redisdata
mountPath: /data
volumes:
- name: redisdata
nfs:
server: 192.168.10.13
path: /data/redis
root@k8s-master01:~/learning-k8s/examples/volumes# kubectl apply -f pod-with-nfs-vol.yaml
pod/redis-nfs-002 created
root@k8s-master01:~/learning-k8s/examples/volumes# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
redis-nfs-002 1/1 Running 0 4s 10.244.2.31 k8s-node01 <none> <none>
- 进入容器查看数据没有丢失,实现跨界点的数据持久性
root@k8s-master01:~/learning-k8s/examples/volumes# kubectl exec -it redis-nfs-002 /bin/sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
/data # ls
dump.rdb test
/data # redis-cli
127.0.0.1:6379> GET mykey
"test"
127.0.0.1:6379>
k8s之持久卷NFS的更多相关文章
- 通过搭建MySQL掌握k8s(Kubernetes)重要概念(上):网络与持久卷
上一篇"通过实例快速掌握k8s(Kubernetes)核心概念"讲解了k8s的核心概念,有了核心概念整个骨架就完整了,应付无状态程序已经够了,但还不够丰满.应用程序分成两种,无状态 ...
- Kubernetes(k8s)存储管理之数据卷volumes(四):持久卷Persistent Volume
目录 一.系统环境 二.前言 三.持久卷(Persistent Volume) 3.1 持久卷(Persistent Volume)概览 3.2 持久卷和持久卷申领的生命周期 3.3 持久卷的类型 3 ...
- K8s的存储卷使用总结
K8s的存储卷: 它有四种存储卷: 1. emptyDir: 空目录,这种存储卷会随着Pod的删除而被清空,它一般作为缓存目录使用,或临时目录, 当做缓存目录时,通常会将一块内存空间映射到该目录上,让 ...
- k8s之存储卷及pvc
1.存储卷概述 因为pod是有生命周期的,pod一重启,里面的数据就没了,所以我们需要数据持久化存储,在k8s中,存储卷不属于容器,而是属于pod,也就是说同一个pod中的容器可以共享一个存储卷,存储 ...
- k8s volume存储卷
k8s volume存储卷 介绍 volume存储卷是Pod中能够被多个容器访问的共享目录,kubernetes的volume概念,用途和目的与docker的volume比较类似,但两者不能等价, ...
- kubernets之持久卷的动态配置
一 介绍持久卷的动态配置原理 前面介绍的pv以及pvc,都需要kubernets集群管理员来支持实际的底层存储,但是kubernets还支持动态配置持久卷来自动化完成这个任务集群管理员可以创建一个持 ...
- 使用 FIO 对 Kubernetes 持久卷进行 Benchmark:读/写(IOPS)、带宽(MB/s)和延迟
工具 Dbench https://github.com/leeliu/dbench 用法 编辑 dbench.yaml 文件中的 storageClassName 以匹配你自己的 Storage C ...
- Alibaba Nacos 学习(五):K8S Nacos搭建,使用nfs
Alibaba Nacos 学习(一):Nacos介绍与安装 Alibaba Nacos 学习(二):Spring Cloud Nacos Config Alibaba Nacos 学习(三):Spr ...
- K8S 使用简单的NFS 作为 持久存储的 StorageClass 的简单测试.
Study From https://jimmysong.io/kubernetes-handbook/practice/using-nfs-for-persistent-storage.html 1 ...
- 如何在Kubernetes集群动态使用 NAS 持久卷
1. 介绍: 本文介绍的动态生成NAS存储卷的方案:在一个已有文件系统上,自动生成一个目录,这个目录定义为目标存储卷: 镜像地址:registry.cn-hangzhou.aliyuncs.com/a ...
随机推荐
- [Linux] rockylinux9.1 的部署使用过程 -- ZFS 虚拟机 cockpit podman samba
备选镜像 | Rocky Linux rocky linux 使用记录 - 个人文章 - SegmentFault 思否 # https://blog.csdn.net/NeverGUM/articl ...
- 修改html5 placeholder文字默认颜色
注意: 1.input后面的冒号不要写错! 2.-moz后面是没有input字样,火狐设置字体颜色为#000,但是他不是全黑,好像有个度似的!(个人认为) input:-ms-input-placeh ...
- Mac上LLAMA2大语言模型安装到使用
LLAMA介绍 LLaMA是由Facebook的母公司Meta AI设计的一个新的大型语言模型.LLaMA拥有70亿到650亿个参数的模型集合,是目前最全面的语言模型之一. Llama是目前唯一一个可 ...
- 记录: OpenAI中转代理API接口服务的使用
由于OpenAI提供服务的地区列表里没有 China,因此想要方便使用OpenAI API的话就需要用到中转服务. 本文介绍的iDataRiver平台便提供这样的API,且比官方OpenAI还要便宜, ...
- 1.Arduino ESP32配置环境
ESP32开发板管理器地址 https://dl.espressif.com/dl/package_esp32_index.json // 无效时可以使用下面这个 https://raw.github ...
- FastWiki v0.1.0发布!新增超多功能
FastWiki 发布 v0.1.0 https://github.com/239573049/fast-wiki/releases/tag/v0.1.0 更新日志 兼容OpenAI接口格式 删除Bl ...
- C#异步编程:原理与实践
一.引言 在现代应用程序开发中,尤其是在涉及I/O操作(如网络请求.文件读写等)时,异步编程成为了提高性能和用户体验的关键技术.C#作为.NET框架下的主流开发语言,提供了强大的异步编程支持,通过as ...
- WPF 图片锯齿解决办法(保证解决!!!)
无非几个属性统统加上,不能解决我倒立洗头,日五档电风扇 RenderOptions.BitmapScalingMode="HighQuality" UseLayoutRoundin ...
- [Java]细节与使用经验
[版权声明]未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) https://www.cnblogs.com/cnb-yuchen/p/18032072 出自[进步*于辰的博客] 纯文字阐述,内 ...
- modelsim常用操作之波形仿真
modelsim波形仿真的新手问题 1.实验目的 在刚接触modelsim时,被其繁复的操作流程所困,一度只能依靠在quartus中修改代码编译后再重启modelsim,自动导入才能得到波形.这样的操 ...