Kubernetes配置映射与Redis

3
我正在按照这个教程设置Redis的ConfigMap。我创建了Redis deployment之后,检查每个pod中是否有redis.conf文件,并确保它们存在。但问题在于,当我进入redis-cli并检查配置时,redis.conf的值并没有被使用。就好像Redis没有启动redis.conf文件一样,而是使用默认值。
maxclients 2000
requirepass "test"

Redis配置文件的ConfigMap

{
    "apiVersion": "v1",
    "data": {
        "redis-config": "maxclients 2000\nrequirepass \"test\"\n\n"
    },
    "kind": "ConfigMap",
    "metadata": {
        "creationTimestamp": "2018-03-07T15:28:19Z",
        "name": "redis-config",
        "namespace": "default",
        "resourceVersion": "2569562",
        "selfLink": "/api/v1/namespaces/default/configmaps/redis-config",
        "uid": "29d250ea-221c-11e8-969f-06c0c8d545d2"
    }
}

k8 Redis清单文件

{
    "kind" : "Deployment",
    "apiVersion" : "extensions/v1beta1",
    "metadata" : {
        "name" : "redis-master",
        "creationTimestamp" : null
    },
    "spec" : {
        "replicas" : 2,
        "template" : {
            "metadata" : {
                "creationTimestamp" : null,
                "labels" : {
                    "app" : "redis",
                    "role" : "master",
                    "tier" : "backend"
                }
            },
            "spec" : {
                "hostNetwork" : true,
                "nodeSelector" :{ "role": "cache"},
                "containers" : [{
                        "name" : "master",
                        "image" : "redis",
                        "ports" : [{
                                "containerPort" : 6379,
                                "hostPort" : 6379,
                                "protocol" : "TCP"
                            }
                        ],
                        "volumeMounts" : [{
                                "mountPath" : "/redis-master",
                                "name": "config"
                            }
                        ],
                        "resources" : {},
                        "terminationMessagePath" : "/dev/termination-log",
                        "imagePullPolicy" : "IfNotPresent"
                    }],
                "volumes" : [{
                    "name" : "config",
                    "configMap" : {
                        "name" : "redis-config",
                        "items": [{
                            "key": "redis-config",
                            "path": "redis.conf"
                        }]
                        }
                    }
                ],    
                "restartPolicy" : "Always",
                "terminationGracePeriodSeconds" : 30,
                "dnsPolicy" : "ClusterFirst",
                "securityContext" : {}
            }
        }
    },
    "status" : {}
}

现在我知道教程使用的是 Pod 类型,而我正在使用 Deployment 类型,但我认为这不是问题所在。
1个回答

3

看起来你正在使用默认的redis容器。如果你查看redis的Dockerfile,例如https://github.com/docker-library/redis/blob/d53b982b387634092c6f11069401679034054ecb/4.0/alpine/Dockerfile,在底部,它们有:

CMD ["redis-server"]

这将使用默认配置启动redis。

根据redis文档: https://redis.io/topics/quickstart 在“启动Redis”部分中,如果您想提供不同的配置,则需要使用以下命令启动redis:

redis-server <config file>

此外,Kubernetes文档中的示例使用了不同的Redis容器:
image: kubernetes/redis

从Dockerfile中看,https://github.com/kubernetes/kubernetes/blob/master/examples/storage/redis/image/Dockerfile似乎是使用提供的配置启动Redis。

谢谢!根据教程更改图像名称并添加环境变量解决了问题。 - bitscuit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接