Skip to content

Commit

Permalink
zfs
Browse files Browse the repository at this point in the history
  • Loading branch information
huataihuang committed Sep 3, 2023
1 parent 35a75fc commit 9401104
Show file tree
Hide file tree
Showing 18 changed files with 285 additions and 3 deletions.
28 changes: 28 additions & 0 deletions source/kubernetes/kubeflow/install_kubeflow_single_command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@

我在 :ref:`y-k8s` 部署的虚拟机中采用了极小化的虚拟磁盘,遇到一个尴尬的问题就是 :ref:`node_pressure_eviction` ,也就是磁盘空间不足导致运行Pod被驱逐。在上述Pods检测就绪发现存在问题时,通过 :ref:`ceph_extend_rbd_drive_with_libvirt_xfs` 实现扩容解决(离线扩展方式,并且将 ``/var/lib/docker`` 迁移到 ``/var/lib/containerd`` )

需要注意,采用这种简单的部署方式,可能仅适用于测试环境。只少我看到的 ``deployments`` 都是单副本,没有提供冗余。后续我再仔细研究一下。

异常排查
=========

在解决了 ref:`y-k8s` 集群的磁盘空间不足问题之后,我清理了 ``ContainerStatusUnknown`` 的pod,然后按照上文依次检查相关 namespace 中pod是否正常运行。

``oidc-authservice`` pending
------------------------------

- 检查 ``kubectl get pods -n istio-system`` 输出显示 ``oidc-authservice-0`` 处于 ``pending`` 状态,检查 ``kubectl -n istio-system describe pods oidc-authservice-0`` 输出如下:

.. literalinclude:: install_kubeflow_single_command/oidc-authservice_pending.yaml
:language: yaml
:caption: ``describe pods oidc-authservice-0`` 可以看到调度失败原因是没有对应 ``pvc``
:emphasize-lines: 33,48

- 检查PVC: ``kubectl -n istio-system get pvc`` 可以看到 ``authservice-pvc`` 处于 ``Pending`` ,则检查 ``kubectl -n istio-system get pvc authservice-pvc -o yaml`` 输出如下:

.. literalinclude:: install_kubeflow_single_command/authservice-pvc.yaml
:language: yaml
:caption: ``get pvc authservice-pvc``

考虑到简单化部署,我采用 :ref:`zfs` 来实现 NFS 输出




参考
=====

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"name":"authservice-pvc","namespace":"istio-system"},"spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"10Gi"}}}}
creationTimestamp: "2023-08-30T14:46:40Z"
finalizers:
- kubernetes.io/pvc-protection
name: authservice-pvc
namespace: istio-system
resourceVersion: "13270831"
uid: 425e321b-20cd-44b4-a797-28f092bfc42a
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
volumeMode: Filesystem
status:
phase: Pending
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Name: oidc-authservice-0
Namespace: istio-system
Priority: 0
Service Account: authservice
Node: <none>
Labels: app=authservice
controller-revision-hash=oidc-authservice-7bd6b4b965
statefulset.kubernetes.io/pod-name=oidc-authservice-0
Annotations: sidecar.istio.io/inject: false
Status: Pending
IP:
IPs: <none>
Controlled By: StatefulSet/oidc-authservice
Containers:
authservice:
Image: gcr.io/arrikto/kubeflow/oidc-authservice:e236439
Port: 8080/TCP
Host Port: 0/TCP
Readiness: http-get http://:8081/ delay=0s timeout=1s period=10s #success=1 #failure=3
Environment Variables from:
oidc-authservice-client Secret Optional: false
oidc-authservice-parameters ConfigMap Optional: false
Environment: <none>
Mounts:
/var/lib/authservice from data (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-khhmb (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: authservice-pvc
ReadOnly: false
kube-api-access-khhmb:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 3m30s (x48 over 4h1m) default-scheduler 0/5 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: 0/5 nodes are available: 5 No preemption victims found for incoming pod..
6 changes: 3 additions & 3 deletions source/kvm/debug/qemu_vfio_connect_timeout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
:language: bash
:caption: 检查 ``nvidia-vgpu-mgr`` 服务状态

果然,再次发现这个服务启动失败...回到了老问题: :ref:`vgpu_unlock` 失效了:
果然,再次发现这个服务启动正常退出(实际上只要执行一次就可以,返回success)。但是,回到了老问题: :ref:`vgpu_unlock` 失效了

查询 ``vgpu`` :

Expand All @@ -39,6 +39,6 @@
:language: bash
:caption: ``nvidia-smi vgpu -q`` 查询vGPU显示只有 ``0`` 个vGPU

我想起来了, :ref:`vgpu_unlock` 需要使用 :ref:`dkms` 模块方式安装 :ref:`vgpu` 驱动。最近依次我升级了内核,内核升级时会重新编译安装 :ref:`vgpu` 模块。我重新检查一遍流程,发现原先修订的过程都正确,但是会不会最近升级的内核支持不稳定呢?
我想起来了, :ref:`vgpu_unlock` 需要使用 :ref:`dkms` 模块方式安装 :ref:`vgpu` 驱动。最近依次我升级了内核,内核升级时会重新编译安装 :ref:`vgpu` 模块。我重新检查一遍流程,发现原先修订的过程都正确

我重新编译了一次 :ref:`vgpu_unlock` (似乎不必),重启服务器
这个问题暂时无解,只要重启一次操作系统,就能恢复激活
1 change: 1 addition & 0 deletions source/linux/storage/filesystem/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Linux文件系统
remount_without_reboot.rst
fstrim.rst
chattr.rst
linux_filename_max_length.rst
xfs/index
ext/index
quota/index
Expand Down
20 changes: 20 additions & 0 deletions source/linux/storage/filesystem/linux_filename_max_length.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. _linux_filename_max_length:

=========================
Linux文件名最大长度
=========================

在生产环境中,总会遇到奇奇怪怪的问题。今天,一个异常长度的文件名导致脚本执行错误,引起我的好奇心,所以记录下Linux文件名最大长度。简单(简化)来说总结如下:

- 文件名的最大长度通常是 ``255`` 个字节(字符)(大多数操作系统都是这样)
- 文件名加路径组合起来最大长度是 ``4096`` 个字节
- 当使用归档和查询操作(我理解为 ``tar`` )最大文件名加路径组合是 ``1024`` 个字节

如果你有疑问,可以参考 `wikipedia: Comparison_of_file_systems#Limits <https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits>`_

参考
======

- `Filename length limits on linux? <https://serverfault.com/questions/9546/filename-length-limits-on-linux>`_
- `File specification syntax <https://www.ibm.com/docs/en/spectrum-protect/8.1.9?topic=parameters-file-specification-syntax>`_
- `Limit on File Name Length in Bash <https://www.baeldung.com/linux/bash-filename-limit>`_
1 change: 1 addition & 0 deletions source/linux/storage/zfs/admin/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ZFS管理的主要手册可以参考:
zfs_admin_prepare.rst
config_zfs_auto_start.rst
zfs_startup.rst
zfs_startup_zcloud.rst
zfs_create_destory_zpool.rst
zfs_compression.rst
zfs_snapshot.rst
Expand Down
7 changes: 7 additions & 0 deletions source/linux/storage/zfs/admin/zfs_admin_prepare.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ ZFS管理准备
:caption: X86移动云ZFS磁盘parted划分分区: 新建的第3个分区作为zpool
:emphasize-lines: 10

完整磁盘用于ZFS
=================

请注意,在前文中,我在模拟系统上都是采用将一块磁盘划分为多个分区,原因只是因为笔记本电脑只有一块磁盘( :ref:`nvme` ),我需要用分区来实现特定目的的ZFS部署。实际上,在生产环境,通常都是完整使用整块磁盘,无需分区。

:ref:`install_kubeflow_single_command` 需要共享存储,我采用 :ref:`ubuntu_zfs` ( :ref:`hpe_dl360_gen9` ) 构建ZFS使用的就是完整物理磁盘

接下来操作
==============

Expand Down
85 changes: 85 additions & 0 deletions source/linux/storage/zfs/admin/zfs_startup_zcloud.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.. _zfs_startup_zcloud:

===================
ZFS快速起步(zcloud)
===================

:ref:`zfs_startup` 是我在 :ref:`docker_zfs_driver` 基础上完成的进一步卷管理。不算完整操作。

现在为了 :ref:`install_kubeflow_single_command` 准备 :ref:`zfs_nfs` ,则是完整的 :ref:`hpe_dl360_gen9` 服务器独立磁盘操作,记录如下

- 在ZFS操作前检查磁盘 ``fdisk -l`` 可以看到磁盘是一个dos分区表,但没有分区(买来时候) :

.. literalinclude:: zfs_startup_zcloud/fdisk_before_zfs
:caption: 在ZFS之前的磁盘是一个dos分区表
:emphasize-lines: 6

- 在独立磁盘 ``/dev/sda`` (这个根据操作系统启动时识别磁盘获得,每个系统可能不同)创建zpool:

.. literalinclude:: zfs_startup_zcloud/zpool_create
:caption: 在磁盘 ``sda`` 上创建ZFS的存储池,名字为 ``zpool-data``

- 检查 ``zpool`` :

.. literalinclude:: zfs_startup_zcloud/zpool_list
:caption: 使用 ``zpool list`` 检查现有的zpool存储池

可以看到输出是一个完整磁盘:

.. literalinclude:: zfs_startup_zcloud/zpool_list_output
:caption: 使用 ``zpool list`` 检查现有的zpool存储池 可以看到刚创建的 ``zpool-data``

- 注意,对于完整磁盘使用,ZFS会立即自动创建 ``GPT`` 分区表(抹掉之前的dos分区表),并且划分为两个分区以及做好类型标注,一切都是自动化的: 使用 ``fdisk -l`` 可以看到如下新的磁盘分区:

.. literalinclude:: zfs_startup_zcloud/fdisk_zfs
:caption: zpool命令在完整磁盘上创建存储池的之后,就可以看到GPT分区以及2个ZFS分区
:emphasize-lines: 10,11

待续...

- 准备在 ``zpool-data`` 下构建一个 ``home`` 卷,挂载到 ``/home`` 目录,这样大多数数据都能够得到有效保存

- 首先以 ``root`` 身份登陆,并确保 ``/home`` 目录没有用户访问,将 ``/home`` 目录重命名:

.. literalinclude:: zfs_startup/rename_home
:language: bash
:caption: 将/home目录重命名(备份)

- 由于 ``zpool-data`` 存储池已经在 :ref:`mobile_cloud_x86_zfs` 构建好,所以忽略创建 ZFS 存储池步骤,直接创建卷 ``home`` ,并且创建 ``home`` 卷下面的子(用户目录):

.. literalinclude:: zfs_startup/zfs_create_volume
:language: bash
:caption: 创建 zpool-data 存储池的 home 卷

对于存储池下创建的 ```` 卷,需要指定挂载目录;对于 ```` 卷下的子卷,可以不指定挂载目录,则会自动按照层次结构进行独立卷挂载,非常巧妙的管理模式

- 完成后使用 ``df -h`` 检查可以看到当前ZFS存储挂载目录:

.. literalinclude:: zfs_startup/zfs_df_hierarchy
:language: bash
:caption: 创建 zpool-data 存储池的 home 卷以及子卷的挂载情况

- 卷和子卷会从上一级ZFS继承属性,由于在 :ref:`mobile_cloud_x86_zfs` 已经配置了 ``zpool-data`` 压缩属性,所以使用 ``zfs get compression`` 可以看到卷和子卷都继承了压缩属性::

# zfs get compression zpool-data/home
NAME PROPERTY VALUE SOURCE
zpool-data/home compression lz4 inherited from zpool-data
# zfs get compression zpool-data/home/huatai
NAME PROPERTY VALUE SOURCE
zpool-data/home/huatai compression lz4 inherited from zpool-data

- 可以设置卷的quota,例如::

zfs set quota=10G zpool-data/home/huatai

- 恢复 ``/home/huatai`` 目录数据:

.. literalinclude:: zfs_startup/restore_home_huatai
:language: bash
:caption: 恢复/home/huatai目录数据

参考
======

- `Oracle Solaris ZFS Administration Guide > Chapter 2 Getting Started With Oracle Solaris ZFS <https://docs.oracle.com/cd/E19253-01/819-5461/setup-1/index.html>`_
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Disk /dev/sda: 1.75 TiB, 1920383410176 bytes, 3750748848 sectors
Disk model: SDLF1CRR-019T-1H
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x33b32403
11 changes: 11 additions & 0 deletions source/linux/storage/zfs/admin/zfs_startup_zcloud/fdisk_zfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Disk /dev/sda: 1.75 TiB, 1920383410176 bytes, 3750748848 sectors
Disk model: SDLF1CRR-019T-1H
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: CB3CD2A0-1D00-D346-B9DA-8ED7E2EEEC89

Device Start End Sectors Size Type
/dev/sda1 2048 3750731775 3750729728 1.7T Solaris /usr & Apple ZFS
/dev/sda9 3750731776 3750748159 16384 8M Solaris reserved 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zpool create zpool-data sda
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zpool list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT
zpool-data 1.73T 456K 1.73T - - 0% 0% 1.00x ONLINE -
1 change: 1 addition & 0 deletions source/linux/storage/zfs/install/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ZFS安装
archlinux_zfs-dkms.rst
archlinux_root_on_zfs.rst
fedora_zfs.rst
ubuntu_zfs.rst

.. only:: subproject and html

Expand Down
40 changes: 40 additions & 0 deletions source/linux/storage/zfs/install/ubuntu_zfs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _ubuntu_zfs:

===================
Ubuntu上运行ZFS
===================

.. note::

本文实践是为 :ref:`install_kubeflow_single_command` 准备NFS共享存储,借这个机会来完成ZFS的完整部署和输出服务

准备工作
=============

我在 :ref:`hpe_dl360_gen9` 二手服务器上安装了一块二手的 :ref:`sandisk_cloudspeed_eco_gen_ii_sata_ssd` ,虽然只是单块磁盘,但是可以用来作为测试环境的数据存储。构建全功能的ZFS,实现数据共享给 :ref:`machine_learning` 这样需要NFS的环境。

注意,我的物理服务器 ``zcloud`` 采用了 :ref:`ubuntu_linux` 22.04,可以采用OpenZFS官方仓库安装

安装
=========

在Ubuntu发行版中,ZFS是包含在默认的Linux内核包中,所以不需要像 :ref:`archlinux_zfs` 通过内核编译支持,只需要安装ZFS utilities。

- 配置 ``/etc/apt/sources.lists`` 确保已经激活了 ``universe`` (可能已经激活):

.. literalinclude:: ubuntu_zfs/sources.list
:caption: 确保 ``/etc/apt/sources.lists`` 已激活 ``universe``
:emphasize-lines: 3

- 安装 ``zfsutils-linux`` :

.. literalinclude:: ubuntu_zfs/install_zfsutils
:caption: 在Ubuntu环境安装 ``zfsutils-linux``

So easy。现在我们可以开始配置

参考
======

- `OpenZFS: Getting Started - Ubuntu <https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/index.html>`_

2 changes: 2 additions & 0 deletions source/linux/storage/zfs/install/ubuntu_zfs/install_zfsutils
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apt update
apt install zfsutils-linux
5 changes: 5 additions & 0 deletions source/linux/storage/zfs/install/ubuntu_zfs/sources.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
deb http://archive.ubuntu.com/ubuntu jammy main restricted
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted
deb http://archive.ubuntu.com/ubuntu jammy universe
deb http://archive.ubuntu.com/ubuntu jammy-updates universe
...

0 comments on commit 9401104

Please sign in to comment.