网站设计工资,宗亲网站开发6,搜索引擎优化包括,网站开发建站微信公众号小程序kubernetes部署redis数据库(单节点)redis简介Redis 是我们常用的非关系型数据库#xff0c;在项目开发、测试、部署到生成环境时#xff0c;经常需要部署一套 Redis 来对数据进行缓存。这里介绍下如何在 Kubernetes 环境中部署用于开发、测试的环境的 Redis 数据库#xff0…kubernetes部署redis数据库(单节点)redis简介Redis 是我们常用的非关系型数据库在项目开发、测试、部署到生成环境时经常需要部署一套 Redis 来对数据进行缓存。这里介绍下如何在 Kubernetes 环境中部署用于开发、测试的环境的 Redis 数据库当然部署的是单节点模式并非用于生产环境的主从、哨兵或集群模式。单节点的 Redis 部署简单且配置存活探针能保证快速检测 Redis 是否可用当不可用时快速进行重启。redis 参数配置在使用 Kubernetes 部署应用后一般会习惯与将应用的配置文件外置用 ConfigMap 存储然后挂载进入镜像内部。这样只要修改 ConfigMap 里面的配置再重启应用就能很方便就能够使应用重新加载新的配置很方便。部署redis创建configmap存储redis配置文件redis-config.yamlkind: ConfigMapapiVersion: v1metadata:name: redis-confignamespace: zisefeizhulabels:app: redisdata:redis.conf: |-dir /dataport 6379bind 0.0.0.0appendonly yesprotected-mode norequirepass zisefeizhupidfile /data/redis-6379.pidRedis 数据存储Kubernetes 部署的应用一般都是无状态应用部署后下次重启很可能会漂移到不同节点上所以不能使用节点上的本地存储而是使用网络存储对应用数据持久化PV 和 PVC 是 Kubernetes 用于与储空关联的资源可与不同的存储驱动建立连接存储应用数据所以接下来我们要创建 Kubernetes PV、PVC 资源。创建 Deployment 部署 Redis创建用于 Kubernetes Deployment 来配置部署 Redis 的参数需要配置 Redis 的镜像地址、名称、版本号还要配置其 CPU 与 Memory 资源的占用配置探针监测应用可用性配置 Volume 挂载之前创建的 PV、PVC、ConfigMap 资源等等内容如下redis-deployment.yaml---apiVersion: v1kind: Servicemetadata:name: redislabels:app: redisspec:type: ClusterIPports:- name: redisport: 6379selector:app: redis---apiVersion: apps/v1kind: Deploymentmetadata:name: redisnamespace: production-pppharmapacklabels:app: redisspec:replicas: 1selector:matchLabels:app: redistemplate:metadata:labels:app: redisspec:# 进行初始化操作修改系统配置解决 Redis 启动时提示的警告信息initContainers:- name: system-initimage: busybox:1.32imagePullPolicy: IfNotPresentcommand:- sh- -c- echo 2048 /proc/sys/net/core/somaxconn echo never /sys/kernel/mm/transparent_hugepage/enabledsecurityContext:privileged: truerunAsUser: 0volumeMounts:- name: sysmountPath: /syscontainers:- name: redisimage: redis:5.0.8command:- sh- -c- redis-server /usr/local/etc/redis/redis.confports:- containerPort: 6379resources:limits:cpu: 1000mmemory: 1024Mirequests:cpu: 1000mmemory: 1024MilivenessProbe:tcpSocket:port: 6379initialDelaySeconds: 300timeoutSeconds: 1periodSeconds: 10successThreshold: 1failureThreshold: 3readinessProbe:tcpSocket:port: 6379initialDelaySeconds: 5timeoutSeconds: 1periodSeconds: 10successThreshold: 1failureThreshold: 3volumeMounts:- name: datamountPath: /data- name: configmountPath: /usr/local/etc/redis/redis.confsubPath: redis.confvolumes:- name: datapersistentVolumeClaim:claimName: zisefeizhu- name: configconfigMap:name: redis-config- name: syshostPath:path: /sys测试redis是否可以正常使用# ctl get pod -n production-pppharmapack | grep redisredis-7768dc9c56-4kp8l 1/1 Running 0 8m43sctl exec -it redis-7768dc9c56-4kp8l -n production-pppharmapack -- /bin/sh# redis-cli127.0.0.1:6379 auth zisefeizhuOK127.0.0.1:6379 config get requirepass1) requirepass2) zisefeizhu到此这篇关于kubernetes环境部署单节点redis数据库的方法的文章就介绍到这了,更多相关kubernetes部署redis数据库内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家