Dyl*_*lan 1 redis docker kubernetes configmap
我正在尝试在 Kubernetes 中部署 redis 哨兵部署。我已经完成了这一点,但希望使用 ConfigMaps 来允许我们更改 sentinel.conf 文件中主服务器的 IP 地址。我启动了此操作,但 Redis 无法写入配置文件,因为 configMap 的挂载点是只读的。
我希望运行一个 init 容器并将 redis conf 复制到 pod 中的另一个目录。但是init容器找不到conf文件。
我有什么选择?初始化容器?除了 ConfigMap 之外还有什么?
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: redis-sentinel
spec:
replicas: 3
template:
metadata:
labels:
app: redis-sentinel
spec:
hostNetwork: true
containers:
- name: redis-sentinel
image: IP/redis-sentinel
ports:
- containerPort: 63790
- containerPort: 26379
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /usr/local/etc/redis/conf
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: sentinel-redis-config
items:
- key: redis-config-sentinel
path: sentinel.conf
Run Code Online (Sandbox Code Playgroud)
根据@P Ekambaram 的建议,你可以尝试这个:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: redis-sentinel
spec:
replicas: 3
template:
metadata:
labels:
app: redis-sentinel
spec:
hostNetwork: true
containers:
- name: redis-sentinel
image: redis:5.0.4
ports:
- containerPort: 63790
- containerPort: 26379
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /usr/local/etc/redis/conf
name: config
initContainers:
- name: copy
image: redis:5.0.4
command: ["bash", "-c", "cp /redis-master/redis.conf /redis-master-data/"]
volumeMounts:
- mountPath: /redis-master
name: config
- mountPath: /redis-master-data
name: data
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: example-redis-config
items:
- key: redis-config
path: redis.conf
Run Code Online (Sandbox Code Playgroud)
在此示例中,initContainer 将文件从 ConfigMap 复制到可写目录中。
笔记:
当 Pod 被分配给节点时,emptyDir 卷首先被创建,并且只要 Pod 在该节点上运行,它就存在。正如其名称所示,它最初是空的。Pod 中的容器都可以读取和写入 emptyDir 卷中的相同文件,尽管该卷可以安装在每个容器中的相同或不同路径上。当 Pod 出于任何原因从节点中删除时,emptyDir 中的数据将被永久删除。
| 归档时间: |
|
| 查看次数: |
10293 次 |
| 最近记录: |