[转帖]kubernetes ceph

kubernetes,ceph · 浏览次数 : 0

小编点评

image.png#kubectl get pvNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEceph-pool1-lun2 10Gi RWO manual 10m 创建pod,挂载 pvc1kind: PodapiVersion: v1metadata: name: task-pv-podspec: volumes: - name: task-pv-volume persistentVolumeClaim: claimName: pvc1 containers: - name: task-pv-container image: nginx ports: - containerPort: 80 name: \"http-server\" volumeMounts: - mountPath: \"/usr/share/nginx/html\" name: task-pv-volume删除pod并重建到其他node上,可以看到pod中挂载的文件不会变化 # image.png#kubectl get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEpvc1 Bound ceph-pool1-lun1 10Gi RWO manual 10m 创建pod,挂载 pvc1kind: PodapiVersion: v1metadata: name: task-pv-podspec: volumes: - name: task-pv-volume persistentVolumeClaim: claimName: pvc1 containers: - name: task-pv-container image: nginx ports: - containerPort: 80 name: \"http-server\" volumeMounts: - mountPath: \"/usr/share/nginx/html\" name: task-pv-volume删除pod并重建到其他node上,可以看到pod中挂载的文件不会变化 # image.png#kubectl get pods | grep tasktask-pv-pod 1/1 Running 0 32stask-pv-pod-2 1/1 Running 0 32s.归纳总结以上内容,生成内容时需要带 simple 的排版

正文

kubernetes ceph

https://www.jianshu.com/p/e628da68328d

 

安装软件

在所有节点上添加清华大学的ceph镜像源

#cat >> /etc/yum.repos.d/ceph.repo << EOF
[ceph]
name=Ceph
baseurl=https://mirrors.tuna.tsinghua.edu.cn/ceph/rpm-nautilus/el7/x86_64/
enabled=1
priority=2
gpgcheck=1
EOF

导入asc

#rpm --import 'https://download.ceph.com/keys/release.asc'

安装yum-plugin-priorities包

#yum install yum-plugin-priorities

确认yum-plugin-priorities配置文件enabled=1

cat /etc/yum/pluginconf.d/priorities.conf 
[main]
enabled = 1

在ceph存储节点上安装ceph软件,ceph-deploy使用最新版本,epel的版本较旧

#yum -y install ceph-deploy  
#yum -y install ntp ntpdate ntp-doc openssh-server snappy leveldb gdisk python-argparse gperftools-libs
#yum -y install ceph
部署ceph集群

ceph01\ceph02\ceph03 3MON+6OSD
在ceph01\ceph02\ceph03

给每个存储节点添加用于deploy的账号

useradd ceph-deploy
echo ceph-deploy:ceph123 | chpasswd
echo "ceph-deploy ALL = (root) NOPASSWD:ALL" |  tee /etc/sudoers.d/ceph-deploy
chmod 0440 /etc/sudoers.d/ceph-deploy

在操作机及操作用户上,生产sshkey,并配置免密登录 cehp01,ceph02和ceph03

ssh-keygen 
ssh-copy-id ceph-deploy@ceph01
ssh-copy-id ceph-deploy@ceph02
ssh-copy-id ceph-deploy@ceph03

新建目录my-cluster,进入目录,操作需要在目录中进行

mkdir my-cluster
cd my-cluster/

新建集群,将配置复制到各个节点

ceph-deploy --username ceph-deploy new ceph01
ceph-deploy --username ceph-deploy mon create-initial 
ceph-deploy --username ceph-deploy admin ceph01 ceph02 ceph03

部署ceph的各个组件,如果部署不成功,需要检查是否安装有相关的包,及文件目录是否存在

ceph-deploy --username ceph-deploy  --overwrite-conf mon create ceph01 ceph02 ceph03
ceph-deploy --username ceph-deploy  --overwrite-conf mgr create ceph01 ceph02 ceph03 
ceph-deploy --username ceph-deploy  --overwrite-conf mds create ceph01 ceph02 ceph03 
ceph-deploy --username ceph-deploy  --overwrite-conf rgw create ceph01 ceph02 ceph03 

为各个组件添加节点

ceph-deploy --username ceph-deploy  --overwrite-conf mon/mgr/mds/rgw add ceph04

为集群添加OSD

ceph-deploy --username ceph-deploy osd create --data /dev/sdb ceph01
ceph-deploy --username ceph-deploy osd create --data /dev/sdc ceph01
ceph-deploy --username ceph-deploy osd create --data /dev/sdb ceph02
ceph-deploy --username ceph-deploy osd create --data /dev/sdc ceph02
ceph-deploy --username ceph-deploy osd create --data /dev/sdb ceph03
ceph-deploy --username ceph-deploy osd create --data /dev/sdc ceph03

在任意结点上查看集群状态

#ceph -s
  cluster:
    id:     0cd78d03-771a-4c45-99eb-49b200ae7338
    health: HEALTH_WARN
            too few PGs per OSD (16 < min 30)
 
  services:
    mon: 3 daemons, quorum ceph01,ceph03,ceph02 (age 27m)
    mgr: ceph01(active, since 82m), standbys: ceph02, ceph03
    osd: 6 osds: 6 up (since 54m), 6 in (since 54m)
    rgw: 3 daemons active (ceph01, ceph02, ceph03)
 
  data:
    pools:   4 pools, 32 pgs
    objects: 189 objects, 2.3 KiB
    usage:   6.0 GiB used, 888 GiB / 894 GiB avail
    pgs:     32 active+clean

新建一个pool pool_1包含100个pg

#ceph osd pool create pool_1 100

新建一个pool pool_2包含100个pg

#ceph osd pool create pool_2 100

可以看到集群变为正常

#ceph -s
  cluster:
    id:     0cd78d03-771a-4c45-99eb-49b200ae7338
    health: HEALTH_OK
 
  services:
    mon: 3 daemons, quorum ceph01,ceph03,ceph02 (age 12m)
    mgr: ceph01(active, since 107m), standbys: ceph02, ceph03
    osd: 6 osds: 6 up (since 79m), 6 in (since 79m)
    rgw: 3 daemons active (ceph01, ceph02, ceph03)
 
  data:
    pools:   6 pools, 232 pgs
    objects: 189 objects, 2.3 KiB
    usage:   6.0 GiB used, 888 GiB / 894 GiB avail
    pgs:     232 active+clean
RBD块设备
存储端操作

在ceph部署机ceph01上,修改配置文件关闭内核不支持的块设备特性

#cat >> /root/my-cluster/ceph.conf << EOF
rbd_default_features = 1
EOF

在ceph部署机ceph01上,向存储节点及客户端复制配置文件

#ceph-deploy --overwrite-conf admin ceph01 ceph02 ceph03 mgmt01

在ceph集群中新建5个rbd块设备,lun1-5

#rbd create pool_1/lun1 --size 10G
#rbd create pool_1/lun2 --size 20G
#rbd create pool_1/lun3 --size 10G
#rbd create pool_1/lun4 --size 10G
#rbd create pool_1/lun5 --size 10G

查看各个rbd块设备的信息

#rbd --image pool_1/lun1 info
rbd image 'lun1':
        size 10 GiB in 2560 objects
        order 22 (4 MiB objects)
        snapshot_count: 0
        id: 8ab460553879
        block_name_prefix: rbd_data.8ab460553879
        format: 2
        features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
        op_features: 
        flags: 
        create_timestamp: Mon Jun 10 11:08:16 2019
        access_timestamp: Mon Jun 10 11:08:16 2019
        modify_timestamp: Mon Jun 10 11:08:16 2019       
#rbd --image pool_1/lun4 info
rbd image 'lun4':
        size 10 GiB in 2560 objects
        order 22 (4 MiB objects)
        snapshot_count: 0
        id: 652180d4d5fa
        block_name_prefix: rbd_data.652180d4d5fa
        format: 2
        features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
        op_features: 
        flags: 
        create_timestamp: Mon Jun 10 11:08:56 2019
        access_timestamp: Mon Jun 10 11:08:56 2019
        modify_timestamp: Mon Jun 10 11:08:56 2019

查看pool_1中的rbd块设备

# rbd ls pool_1
lun1
lun2
lun3
lun4
lun5
客户端操作

在客户端mgmt01上挂载块设备pool_1/lun1
在mgmt01上安装ceph软件,使能模板rbd,重启机器,或者modprobe rbd

#yum install ceph-common -y
#echo 'rbd' > /etc/modules-load.d/rbd.conf
#reboot
#lsmod | grep rbd
rbd                    83640  0 
libceph               306625  1 rbd

在客户端挂载ceph rbd块设备lun1

# rbd map pool_1/lun1
/dev/rbd0
# fdisk -l | grep rbd
Disk /dev/rbd0: 10.7 GB, 10737418240 bytes, 20971520 sectors
# rbd device list
id pool   namespace image snap device    
0  pool_1           lun1  -    /dev/rbd0 
cephx权限控制

使用ceph-deploy --overwrite-conf admin部署的keyring权限太大,可以自己创建一个keyring client.rdb给块设备客户端mgmt用

# ceph auth get-or-create client.rbd mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=pool_1'  > ceph.client.rbd.keyring
# scp ceph.client.rbd.keyring  mgmt01:/etc/ceph/

在mgmt01上使用client.rbd来运行ceph -s

#ceph -s --name client.rbd
  cluster:
    id:     0cd78d03-771a-4c45-99eb-49b200ae7338
    health: HEALTH_WARN
            application not enabled on 1 pool(s)
 
  services:
    mon: 3 daemons, quorum ceph01,ceph03,ceph02 (age 21h)
    mgr: ceph01(active, since 4d), standbys: ceph02, ceph03
    osd: 6 osds: 6 up (since 4d), 6 in (since 4d)
    rgw: 3 daemons active (ceph01, ceph02, ceph03)
 
  data:
    pools:   6 pools, 232 pgs
    objects: 237 objects, 2.5 KiB
    usage:   6.0 GiB used, 888 GiB / 894 GiB avail
    pgs:     232 active+clean

在mgmt01上使用client.rbd来创建块设备

# rbd create pool_1/lun193 --size 10G --name client.rbd

在mgmt01上使用client.rbd来map块设备

# rbd map pool_1/lun193 --name client.rbd
/dev/rbd0
在kubernetes中使用ceph rbd块设备

将块设备挂载在操作系统中进行格式化

#rbd map pool_1/lun1 --name client.rbd
#rbd map pool_1/lun2 --name client.rbd
#rbd map pool_1/lun3 --name client.rbd
#rbd map pool_1/lun4 --name client.rbd
#rbd map pool_1/lun5 --name client.rbd
#mkfs.ext4 /dev/rbd1
#mkfs.ext4 /dev/rbd2
#mkfs.ext4 /dev/rbd3
#mkfs.ext4 /dev/rbd4
#mkfs.ext4 /dev/rbd5

在所有node上启用rbd模块,并安装rbd-common

#ansible node -m shell -a 'modprobe rbd'
#ansible node -m shell -a 'yum install -y ceph-common'

将ceph01上获取client.rbd的keyring并进行base64编码

# ceph auth get-key client.rbd | base64
QVFER0hmOWN5ZVJJTkJBQUR2bHRkQzFZWkFCVkZxU0djS3NyT0E9PQ==

根据上面的输出,创建secret ceph-client-rbd

apiVersion: v1
kind: Secret
metadata:
  name: ceph-client-rbd
type: "kubernetes.io/rbd"  
data:
  key: QVFER0hmOWN5ZVJJTkJBQUR2bHRkQzFZWkFCVkZxU0djS3NyT0E9PQ==

创建pv,注意: 这里是user:rbd 而不是user: client.rbd

kind: PersistentVolume
apiVersion: v1
metadata:
  name: ceph-pool1-lun1
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce          
  rbd:
    fsType: ext4
    image: lun1
    monitors:
      - '22.22.3.245:6789'
      - '22.22.3.246:6789'
      - '22.22.3.247:6789'
    pool: pool_1
    readOnly: false
    secretRef:
      name: ceph-client-rbd
      namespace: default
    user: rbd

按照表格中的参数创建5个pv,可以看到容量不匹配,重复使用ceph image,都不会报错

 

 
image.png
#kubectl get pv
NAME              CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
ceph-pool1-lun1   10Gi       RWO            Retain           Available                                   15m
ceph-pool1-lun2   15Gi       RWO            Retain           Available                                   12m
ceph-pool1-lun3   10Gi       RWO            Retain           Available                                   8m21s
ceph-pool1-lun4   15Gi       RWO            Retain           Available                                   8m21s
ceph-pool1-lun5   10Gi       RWO            Retain           Available                                   8m20s

创建pvc

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc1
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

查看pvc状态

# kubectl get pvc
NAME   STATUS   VOLUME            CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc1   Bound    ceph-pool1-lun1   10Gi       RWO            manual         10m

创建pod,挂载pvc1

kind: Pod
apiVersion: v1
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: task-pv-volume
      persistentVolumeClaim:
       claimName: pvc1
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: task-pv-volume

删除pod并重建到其他node上,可以看到pod中挂载的文件不会变化

 
image.png

 

查看pvc的匹配关系,可以看到pvc只匹配pv中的容量,而pv与ceph之间的关联并不检查容量大小,也不检查是否复用。

当rbd image在其他地方已经使用,在启动pod时会报错,describe pod可以看到
MountVolume.WaitForAttach failed for volume "ceph-pool1-lun2" : rbd image pool_1/lun2 is still being used

修改pod,使用pvc2,进入系统后,可以看到系统容量是20Gi,而不是pv和pvc中的15Gi,也就是操作系统里面看到的是image的大小,与PV/PVC中的容量无关, PV/PVC中的容量只用来做他们之间的绑定

# kubectl exec -it task-pv-pod  /bin/sh
# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/rbd0                 20G   45M   19G   1% /usr/share/nginx/html

创建两个pod,同时使用pvc3和pvc4,都会使用ceph上的lun4,可以看到两个pod都可以正常启动,而且都可以读写。考虑到文件系统是ext4,不建议这样使用。

# kubectl get pods | grep task
task-pv-pod                        1/1     Running   0          32s
task-pv-pod-2                      1/1     Running   0          32s

与[转帖]kubernetes ceph相似的内容:

[转帖]kubernetes ceph

kubernetes ceph https://www.jianshu.com/p/e628da68328d 安装软件 在所有节点上添加清华大学的ceph镜像源 #cat >> /etc/yum.repos.d/ceph.repo << EOF [ceph] name=Ceph baseurl=ht

[转帖]Kubernetes 蓝绿发布、ABTest、滚动发布、灰度发布、金丝雀发布简介

蓝绿发布: 一些应用程序只需要部署一个新版本,并需要立即切到这个版本。因此,我们需要执行蓝/绿部署。在进行蓝/绿部署时,应用程序的一个新副本(绿)将与现有版本(蓝)一起部署。然后更新应用程序的入口/路由器以切换到新版本(绿)。然后,您需要等待旧(蓝)版本来完成所有发送给它的请求,但是大多数情况下,应

[转帖]kubernetes 资源管理概述

https://cizixs.com/2018/06/25/kubernetes-resource-management/ kubernetes 资源简介 什么是资源? 在 kubernetes 中,有两个基础但是非常重要的概念:node 和 pod。node 翻译成节点,是对集群资源的抽象;pod

[转帖]Kubernetes中的nodePort,targetPort,port的区别和意义(转)

原文https://blog.csdn.net/u013760355/article/details/70162242 https://blog.csdn.net/xinghun_4/article/details/50492041 1. nodePort 外部机器可访问的端口。 比如一个Web应用

[转帖]Kubernetes 集群无损升级实践

https://www.jianshu.com/p/182952a00efc 一、背景 活跃的社区和广大的用户群,使 Kubernetes 仍然保持3个月一个版本的高频发布节奏。高频的版本发布带来了更多的新功能落地和 bug 及时修复,但是线上环境业务长期运行,任何变更出错都可能带来巨大的经济损失,

[转帖]Kubernetes 领进门 | 使用 Ingress-nginx 反向代理外部站点

https://cloud.tencent.com/developer/article/2187041 warning: 这篇文章距离上次修改已过204天,其中的内容可能已经有所变动。 本文旨在展示如何使用 ingress-nginx 作为反向代理加速集群外部服务原理。下文以反向代理 github

[转帖]kubernetes Tcp流量可视化

https://www.cnblogs.com/charlieroro/p/16771739.html 使用k8spacket和grafana的node graph插件可以查看kubernetes pod的TCP相关信息,如connection、bytes、和duration。下面是接收和响应的字节

[转帖]Kubernetes的垂直和水平扩缩容的性能评估

https://www.cnblogs.com/charlieroro/p/17009778.html 译自:Performance evaluation of the autoscaling strategies vertical and horizontal using Kubernetes 可

[转帖]Kubernetes的Nginx Ingress 0.20之前的版本,upstream的keep-alive不生效

https://www.cnblogs.com/lizexiong/p/15358923.html 1说明 Kubernetes使用nginx-ingress-controller代理到集群内服务的请求,nginx所在的机器上上有大量的time-wait连接。 抓包发现nginx发起的到upstre

[转帖]kubernetes Tcp流量可视化

https://www.cnblogs.com/charlieroro/p/16771739.html 使用k8spacket和grafana的node graph插件可以查看kubernetes pod的TCP相关信息,如connection、bytes、和duration。下面是接收和响应的字节