当前位置: 首页 > news >正文

K8S - Java微服务配置 - 使用ConfigMap配置redis

参考文档:https://v1-27.docs.kubernetes.io/zh-cn/docs/tutorials/configuration/configure-redis-using-configmap/

cat <<EOF >./example-redis-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:name: example-redis-config
data:redis-config: ""
EOF#由 spec.volumes[1] 创建一个名为 config 的卷
#spec.volumes[1].items[0] 下的 key 和 path 会将来自 example-redis-config ConfigMap 中的 redis-config 密钥公开在 config 卷上一个名为 redis.conf 的文件中。
#然后 config 卷被 spec.containers[0].volumeMounts[1] 挂载在 /redis-master。
#pod内容示例:
apiVersion: v1
kind: Pod
metadata:name: redis
spec:containers:- name: redisimage: redis:5.0.4command:- redis-server- "/redis-master/redis.conf"env:- name: MASTERvalue: "true"ports:- containerPort: 6379resources:limits:cpu: "0.1"volumeMounts:- mountPath: /redis-master-dataname: data- mountPath: /redis-mastername: configvolumes:- name: dataemptyDir: {}- name: configconfigMap:name: example-redis-configitems:- key: redis-configpath: redis.conf#创建configmap
kubectl apply -f example-redis-config.yaml
#创建pod redis
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml

在这里插入图片描述
又来这个错?搜了下默认是从docker hub拉取,可能是仓库地址的配置问题,这里先不纠结这个
我们更新下直接拉取docker的 reids 镜像

yum update -y
yum makecache
docker pull redis# 运行后进入pod
kubectl apply -f redis-pod.yaml
kubectl exec -it redis -- redis-cli

在这里插入图片描述
通过ConfigMap修改redis配置

[root@weihengmaster1 configmap]# vim example-redis-config.yaml 
#添加 maxmemory 和 maxmemory-policy 配置项
apiVersion: v1
kind: ConfigMap
metadata:name: example-redis-config
data:redis-config: |maxmemory 2mbmaxmemory-policy allkeys-lru   #修改后别忘了更新到 configmap 资源中
[root@weihengmaster1 configmap]# kubectl apply -f example-redis-config.yaml
configmap/example-redis-config configured
[root@weihengmaster1 configmap]# 

更新成功:
在这里插入图片描述

测试完毕清理资源
kubectl delete pod/redis configmap/example-redis-config


http://www.mrgr.cn/news/9663.html

相关文章:

  • Excel VBA 编程学习指南,1.2 VBA与Excel的关系
  • 前端宝典十九:高频算法之动态规划
  • (第三十三天)
  • 判断变量是否为数组
  • 案例-登录认证
  • RFID光触发标签在物流仓储的深度应用与技术优势解读
  • flutter GestureDetector 的 behavior属性
  • 设计模式 2 抽象工厂模式
  • Android strings.xml中定义字符串显示空格
  • C++设计模式3:工厂模式
  • Python和MATLAB梯度下降导图
  • 【数据结构-前缀异或和】力扣1177. 构建回文串检测
  • Edge-TTS:微软推出的,免费、开源、支持多种中文语音语色的AI工具[工具版]
  • ts 自动化编译
  • 【脏数据 bug 解决】ValueError: mean must have 1 elements if it is an iterable, got 3
  • 第134天:内网安全-横向移动NTLM-Relay重放Responder中继攻击LdapEws
  • 示波器输出的csv文件如何转换为频谱图及其excel表格(频率与幅值)
  • msxml*.dll 错误 ‘80072f7d‘ 安全频道支持出错 解决方案
  • MySQL 用户与权限管理详解
  • LVS+Keepalived集群(主、备)