Dragonfly之K8s容器化部署

2022年9月9日 294点热度 0人点赞 0条评论

Dragonfly memory store(后简称Dragonfly)做为Redis的替代方案,70+天内,在GitHub上达到了200+ fork和11k+ star。而Redis因为只能利用一个CPU core,而久为业内所诟病。

天下苦Redis久矣。


做为开篇,本文对Dragonfly基于Kubernetes环境的部署进行演示和简单测试。在生产环境中,需结合具体要求,增加和调整相应的配置。本篇文档只涵盖最基本的部署需要。


架构图

图片

实验环境所使用的主要组件:

AWS EKS:v1.23

Worker node

AMI: Amazon EKS optimized Linux AMI, CPU architecture: x86_64

Instance size: t3a.medium

创建Dragonfly的K8s deployment

kubectl create deploy dragonfly --image=docker.dragonflydb.io/dragonflydb/dragonfly

创建K8s service

vim dragonfly_service.yaml

apiVersion: v1kind: Servicemetadata:  name: dragonfly  namespace: blogspec:  selector:    app: dragonfly  ports:    - port: 6379      targetPort: 6379


kubectl apply -f dragonfly_service.yaml

查看deployment的部署结果

 % kubectl get podNAME                        READY   STATUS             RESTARTS      AGEdragonfly-74899bcc4-wrfqj   1/2     CrashLoopBackOff   4 (43s ago)   2m25s

此时Dragonfly Pod没有成功创建。

排查问题,查看Pod日志

% kubectl logs dragonfly-74899bcc4-wrfqjI20220909 13:41:18.250780     1 init.cc:56] dragonfly running in opt mode.  1 apiVersion: v1I20220909 13:41:18.250833     1 dfly_main.cc:219] Starting dragonfly df-v0.7.0-a43badf50c77a67f7bfef37a08e047d42f62f96aE20220909 13:41:18.250849     1 dfly_main.cc:233] Kernel 5.10 or later is supported. Exiting...


失败的原因与Linux中使用了一个名为io-uring的新的API有关。(https://github.com/dragonflydb/dragonfly#running-the-server

Dragonfly runs on linux. It uses relatively new linux specific io-uring API for I/O, hence it requires Linux version 5.10 or later. Debian/Bullseye, Ubuntu 20.04.4 or later fit these requirements.

究其原因,Amazon EKS optimized Linux AMI的kernel默认为5.4。


解决办法:

将Amazon Linux 2(Amazon Linux Extras)内核从5.4.x升级到5.10.x。

步骤:

查看处于活动状态的内核:

uname -r

5.4.204-113.362.amzn2.x86_64

使用amazon-linux-extras工具验证可用的内核版本:

amazon-linux-extras | grep kernel

 49  kernel-5.4=latest        enabled      [ =stable ]  _  kernel-5.10              available    [ =stable ]  _  kernel-5.15              available    [ =stable ]

当前kernel-5.4处于enabled的状态。

使用amazon-linux-extras工具停用内核5.4:

amazon-linux-extras disable kernel-5.4

Beware that disabling topics is not supported after they are installed.  0  ansible2                 available    \        [ =2.4.2  =2.4.6  =2.8  =stable ]  2  httpd_modules            available    [ =1.0  =stable ]  3  memcached1.5             available    \        [ =1.5.1  =1.5.16  =1.5.17 ]  5  postgresql9.6            available    \        [ =9.6.6  =9.6.8  =stable ]  6  postgresql10             available    [ =10  =stable ]  9  R3.4                     available    [ =3.4.3  =stable ] 10  rust1                    available    \        [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0  =1.38.0          =stable ] 11  vim                      available    [ =8.0  =stable ] 18  libreoffice              available    \        [ =5.0.6.2_15  =5.3.6.1  =stable ] 19  gimp                     available    [ =2.8.22 ] 20  docker=latest            enabled      \        [ =17.12.1  =18.03.1  =18.06.1  =18.09.9  =stable ] 21  mate-desktop1.x          available    \        [ =1.19.0  =1.20.0  =stable ] 22  GraphicsMagick1.3        available    \        [ =1.3.29  =1.3.32  =1.3.34  =stable ] 23  tomcat8.5                available    \        [ =8.5.31  =8.5.32  =8.5.38  =8.5.40  =8.5.42  =8.5.50          =stable ] 24  epel                     available    [ =7.11  =stable ] 25  testing                  available    [ =1.0  =stable ] 26  ecs                      available    [ =stable ] 27  corretto8                available    \        [ =1.8.0_192  =1.8.0_202  =1.8.0_212  =1.8.0_222  =1.8.0_232          =1.8.0_242  =stable ] 28  firecracker              available    [ =0.11  =stable ] 29  golang1.11               available    \        [ =1.11.3  =1.11.11  =1.11.13  =stable ] 30  squid4                   available    [ =4  =stable ] 32  lustre2.10               available    \        [ =2.10.5  =2.10.8  =stable ] 33  java-openjdk11           available    [ =11  =stable ] 34  lynis                    available    [ =stable ] 36  BCC                      available    [ =0.x  =stable ] 37  mono                     available    [ =5.x  =stable ] 38  nginx1                   available    [ =stable ] 39  ruby2.6                  available    [ =2.6  =stable ] 40  mock                     available    [ =stable ] 41  postgresql11             available    [ =11  =stable ] 42  php7.4                   available    [ =stable ] 43  livepatch                available    [ =stable ] 44  python3.8                available    [ =stable ] 45  haproxy2                 available    [ =stable ] 46  collectd                 available    [ =stable ] 47  aws-nitro-enclaves-cli   available    [ =stable ] 48  R4                       available    [ =stable ] 49  kernel-5.4               available    [ =stable ] 50  selinux-ng               available    [ =stable ] 51  php8.0                   available    [ =stable ] 52  tomcat9                  available    [ =stable ] 53  unbound1.13              available    [ =stable ] 54  mariadb10.5              available    [ =stable ] 55  kernel-5.10              available    [ =stable ] 56  redis6                   available    [ =stable ] 57  ruby3.0                  available    [ =stable ] 58  postgresql12             available    [ =stable ] 59  postgresql13             available    [ =stable ] 60  mock2                    available    [ =stable ] 61  dnsmasq2.85              available    [ =stable ] 62  kernel-5.15              available    [ =stable ] 63  postgresql14             available    [ =stable ] 64  firefox                  available    [ =stable ] 65  lustre                   available    [ =stable ]

注意:如果没有停用内核5.4,则会在尝试安装内核5.10时收到以下错误信息:

Refusing because kernel-5.10 could cause an invalid combination.

使用amazon-linux-extras工具安装内核5.10:

amazon-linux-extras install kernel-5.10 -y

Installing kernelLoaded plugins: priorities, update-motd, versionlockCleaning repos: amzn2-core amzn2extra-docker amzn2extra-kernel-5.1012 metadata files removed4 sqlite files removed0 metadata files removedLoaded plugins: priorities, update-motd, versionlockamzn2-core                                                                                                                                                                                                    | 3.7 kB  00:00:00amzn2extra-docker                                                                                                                                                                                             | 3.0 kB  00:00:00amzn2extra-kernel-5.10                                                                                                                                                                                        | 3.0 kB  00:00:00(1/7): amzn2-core/2/x86_64/group_gz                                                                                                                                                                           | 2.5 kB  00:00:00(2/7): amzn2-core/2/x86_64/updateinfo                                                                                                                                                                         | 495 kB  00:00:00(3/7): amzn2extra-docker/2/x86_64/primary_db                                                                                                                                                                  |  93 kB  00:00:00(4/7): amzn2extra-kernel-5.10/2/x86_64/updateinfo                                                                                                                                                             |  18 kB  00:00:00(5/7): amzn2extra-docker/2/x86_64/updateinfo                                                                                                                                                                  | 6.4 kB  00:00:00(6/7): amzn2extra-kernel-5.10/2/x86_64/primary_db                                                                                                                                                             |  11 MB  00:00:00(7/7): amzn2-core/2/x86_64/primary_db                                                                                                                                                                         |  65 MB  00:00:00Resolving Dependencies--> Running transaction check---> Package kernel.x86_64 0:5.10.135-122.509.amzn2 will be installed--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================================================================================================================================================== Package Arch Version Repository Size=====================================================================================================================================================================================================================================Installing: kernel x86_64 5.10.135-122.509.amzn2 amzn2extra-kernel-5.10 32 M
Transaction Summary=====================================================================================================================================================================================================================================Install 1 Package
Total download size: 32 MInstalled size: 134 MDownloading packages:Delta RPMs disabled because /usr/bin/applydeltarpm not installed.kernel-5.10.135-122.509.amzn2.x86_64.rpm | 32 MB 00:00:00Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : kernel-5.10.135-122.509.amzn2.x86_64 1/1 Verifying : kernel-5.10.135-122.509.amzn2.x86_64 1/1
Installed: kernel.x86_64 0:5.10.135-122.509.amzn2
Complete! 0 ansible2 available \ [ =2.4.2 =2.4.6 =2.8 =stable ] 2 httpd_modules available [ =1.0 =stable ] 3 memcached1.5 available \ [ =1.5.1 =1.5.16 =1.5.17 ] 5 postgresql9.6 available \ [ =9.6.6 =9.6.8 =stable ] 6 postgresql10 available [ =10 =stable ] 9 R3.4 available [ =3.4.3 =stable ] 10 rust1 available \ [ =1.22.1 =1.26.0 =1.26.1 =1.27.2 =1.31.0 =1.38.0 =stable ] 11 vim available [ =8.0 =stable ] 18 libreoffice available \ [ =5.0.6.2_15 =5.3.6.1 =stable ] 19 gimp available [ =2.8.22 ] 20 docker=latest enabled \ [ =17.12.1 =18.03.1 =18.06.1 =18.09.9 =stable ] 21 mate-desktop1.x available \ [ =1.19.0 =1.20.0 =stable ] 22 GraphicsMagick1.3 available \ [ =1.3.29 =1.3.32 =1.3.34 =stable ] 23 tomcat8.5 available \ [ =8.5.31 =8.5.32 =8.5.38 =8.5.40 =8.5.42 =8.5.50 =stable ] 24 epel available [ =7.11 =stable ] 25 testing available [ =1.0 =stable ] 26 ecs available [ =stable ] 27 corretto8 available \ [ =1.8.0_192 =1.8.0_202 =1.8.0_212 =1.8.0_222 =1.8.0_232 =1.8.0_242 =stable ] 28 firecracker available [ =0.11 =stable ] 29 golang1.11 available \ [ =1.11.3 =1.11.11 =1.11.13 =stable ] 30 squid4 available [ =4 =stable ] 32 lustre2.10 available \ [ =2.10.5 =2.10.8 =stable ] 33 java-openjdk11 available [ =11 =stable ] 34 lynis available [ =stable ] 36 BCC available [ =0.x =stable ] 37 mono available [ =5.x =stable ] 38 nginx1 available [ =stable ] 39 ruby2.6 available [ =2.6 =stable ] 40 mock available [ =stable ] 41 postgresql11 available [ =11 =stable ] 42 php7.4 available [ =stable ] 43 livepatch available [ =stable ] 44 python3.8 available [ =stable ] 45 haproxy2 available [ =stable ] 46 collectd available [ =stable ] 47 aws-nitro-enclaves-cli available [ =stable ] 48 R4 available [ =stable ] _ kernel-5.4 available [ =stable ] 50 selinux-ng available [ =stable ] 51 php8.0 available [ =stable ] 52 tomcat9 available [ =stable ] 53 unbound1.13 available [ =stable ] 54 mariadb10.5 available [ =stable ] 55 kernel-5.10=latest enabled [ =stable ] 56 redis6 available [ =stable ] 57 ruby3.0 available [ =stable ] 58 postgresql12 available [ =stable ] 59 postgresql13 available [ =stable ] 60 mock2 available [ =stable ] 61 dnsmasq2.85 available [ =stable ] 62 kernel-5.15 available [ =stable ] 63 postgresql14 available [ =stable ] 64 firefox available [ =stable ] 65 lustre available [ =stable ]

从RPM数据库验证已安装的内核:

rpm -qa | grep kernel

kernel-5.4.204-113.362.amzn2.x86_64kernel-5.10.135-122.509.amzn2.x86_64

重启实例以激活最新的内核

reboot

登录并确认内核已激活

uname -r

5.10.135-122.509.amzn2.x86_64

查看K8s service信息

% kubectl get svcNAME        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGEdragonfly   ClusterIP   172.20.xx.yyy   <none>        6379/TCP   2m15s

记录service的IP地址,后面测试Dragonfly功能时,会使用此IP访问Dragonfly。

测试:(本测试不涉及应用集成测试部分)

登陆到worker node。

安装Redis CLI

amazon-linux-extras install redis6

使用上面步骤获取到的service的IP和6379端口,连接Dragonfly并验证功能

redis-cli -h 172.20.x.y -p 6379

172.20.x.y:6379set hello worldOK172.20.x.y:6379keys *1) "hello"172.20.x.y:6379get hello"world"

References

https://github.com/dragonflydb/dragonfly

85770Dragonfly之K8s容器化部署

这个人很懒,什么都没留下

文章评论