将RedisInsight连接到部署在minikube中的redis数据库

问题描述 投票:0回答:1

所以我已经使用 Helm Chart Bitnami 在 minikube 中部署了 Redis 数据库服务

https://github.com/bitnami/charts/tree/main/bitnami/redis

但是我无法将其与redisinsight连接

kubectl get services --all-namespaces

NAMESPACE              NAME                        TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                kubernetes                  ClusterIP      10.96.0.1        <none>        443/TCP                  2d10h
default                redisinsight-service        LoadBalancer   10.103.32.34     <pending>     80:31196/TCP             40m
kube-system            kube-dns                    ClusterIP      10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   2d10h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP      10.106.115.247   <none>        8000/TCP                 2d10h
kubernetes-dashboard   kubernetes-dashboard        ClusterIP      10.111.250.58    <none>        80/TCP                   2d10h
prefect                prefect-postgresql          ClusterIP      10.106.145.244   <none>        5432/TCP                 39h
prefect                prefect-postgresql-hl       ClusterIP      None             <none>        5432/TCP                 39h
prefect                prefect-server              ClusterIP      10.110.247.9     <none>        4200/TCP                 39h
redis                  redis-headless              ClusterIP      None             <none>        6379/TCP                 10h
redis                  redis-master                ClusterIP      10.96.27.187     <none>        6379/TCP                 10h
redis                  redis-replicas              ClusterIP      10.104.12.70     <none>        6379/TCP                 10h

kubectl get pod --all-namespaces -o wide
NAMESPACE              NAME                                         READY   STATUS    RESTARTS        AGE     IP             NODE       NOMINATED NODE   READINESS GATES
default                redisinsight-9dc76bb66-hhf75                 1/1     Running   0               12h     10.244.0.17    minikube   <none>           <none>
kube-system            coredns-5d78c9869d-kth76                     1/1     Running   0               2d22h   10.244.0.2     minikube   <none>           <none>
kube-system            etcd-minikube                                1/1     Running   0               2d22h   192.168.49.2   minikube   <none>           <none>
kube-system            kube-apiserver-minikube                      1/1     Running   0               2d22h   192.168.49.2   minikube   <none>           <none>
kube-system            kube-controller-manager-minikube             1/1     Running   0               2d22h   192.168.49.2   minikube   <none>           <none>
kube-system            kube-proxy-m8zht                             1/1     Running   0               2d22h   192.168.49.2   minikube   <none>           <none>
kube-system            kube-scheduler-minikube                      1/1     Running   0               2d22h   192.168.49.2   minikube   <none>           <none>
kube-system            storage-provisioner                          1/1     Running   1 (2d22h ago)   2d22h   192.168.49.2   minikube   <none>           <none>
kubernetes-dashboard   dashboard-metrics-scraper-5dd9cbfd69-lsj94   1/1     Running   0               2d22h   10.244.0.4     minikube   <none>           <none>
kubernetes-dashboard   kubernetes-dashboard-5c5cfc8747-j66x2        1/1     Running   0               2d22h   10.244.0.3     minikube   <none>           <none>
local-path-storage     local-path-provisioner-bf548cc96-q2vb4       1/1     Running   0               15h     10.244.0.16    minikube   <none>           <none>
prefect                prefect-postgresql-0                         1/1     Running   0               2d3h    10.244.0.10    minikube   <none>           <none>
prefect                prefect-server-6f58d4bd95-rbh5c              1/1     Running   0               2d3h    10.244.0.11    minikube   <none>           <none>
redis                  redis-master-0                               1/1     Running   0               22h     10.244.0.13    minikube   <none>           <none>
redis                  redis-replicas-0                             1/1     Running   0               22h     10.244.0.12    minikube   <none>           <none>
redis                  redis-replicas-1                             1/1     Running   0               22h     10.244.0.14    minikube   <none>           <none>
redis                  redis-replicas-2                             1/1     Running   0               22h     10.244.0.15    minikube   <none>           <none>

我首先尝试使用 redis-master 上的 portforward 连接桌面应用程序:

kubectl port-forward -n redis svc/redis-master 8080:6379
Forwarding from 127.0.0.1:8080 -> 6379
Forwarding from [::1]:8080 -> 6379
Handling connection for 8080

redis服务说明:

kubectl describe service redis -n redis
Name:              redis-headless
Namespace:         redis
Labels:            app.kubernetes.io/instance=redis
                   app.kubernetes.io/managed-by=Helm
                   app.kubernetes.io/name=redis
                   helm.sh/chart=redis-17.14.3
Annotations:       <none>
Selector:          app.kubernetes.io/instance=redis,app.kubernetes.io/name=redis
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                None
IPs:               None
Port:              tcp-redis  6379/TCP
TargetPort:        redis/TCP
Endpoints:         10.244.0.12:6379,10.244.0.13:6379,10.244.0.14:6379 + 1 more...
Session Affinity:  None
Events:            <none>

Name:              redis-master
Namespace:         redis
Labels:            app.kubernetes.io/component=master
                   app.kubernetes.io/instance=redis
                   app.kubernetes.io/managed-by=Helm
                   app.kubernetes.io/name=redis
                   helm.sh/chart=redis-17.14.3
Annotations:       <none>
Selector:          app.kubernetes.io/component=master,app.kubernetes.io/instance=redis,app.kubernetes.io/name=redis
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.96.27.187
IPs:               10.96.27.187
Port:              tcp-redis  6379/TCP
TargetPort:        redis/TCP
Endpoints:         10.244.0.13:6379
Session Affinity:  None
Events:            <none>

Name:              redis-replicas
Namespace:         redis
Labels:            app.kubernetes.io/component=replica
                   app.kubernetes.io/instance=redis
                   app.kubernetes.io/managed-by=Helm
                   app.kubernetes.io/name=redis
                   helm.sh/chart=redis-17.14.3
Annotations:       <none>
Selector:          app.kubernetes.io/component=replica,app.kubernetes.io/instance=redis,app.kubernetes.io/name=redis
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.104.12.70
IPs:               10.104.12.70
Port:              tcp-redis  6379/TCP
TargetPort:        redis/TCP
Endpoints:         10.244.0.12:6379,10.244.0.14:6379,10.244.0.15:6379
Session Affinity:  None
Events:            <none>

当我尝试在 Redis Insight UI 中连接到 Redis 时,我得到了这个(我也直接在 Pod 上尝试了端口转发,而不是在服务上)

主机:127.0.0.1 端口:8080 没有密码

之后我直接在我的minikube中部署了redisinsight并尝试将其与内部主机连接 第一个 yaml https://docs.redis.com/latest/ri/installing/install-k8s/

我的脚本 pulumi-python 在其中声明了 redis 数据库的 helm 图表部署:

import pulumi


from pulumi_kubernetes import Provider
from pulumi_kubernetes.helm.v3 import Chart, ChartOpts,FetchOpts
from pulumi_kubernetes.core.v1 import Namespace
from functions import ConfigYML


redis_namespace = Namespace("redis",metadata={'name':"redis"})



redis_chart = Chart(
    "redis",
    ChartOpts(
        chart="redis",
        fetch_opts=FetchOpts(
            repo="https://charts.bitnami.com/bitnami",  # Updated repository
        ),

        namespace=redis_namespace.metadata["name"],
        values={
            "usePassword": False,
        },
    ),
    pulumi.ResourceOptions(depends_on=[redis_namespace])
)

usePassword
false
我不应该设置任何密码 此外,在我的终端中,当我尝试使用
redis-cli
命令连接到数据库时,它似乎正在工作

redis-cli -h localhost -p 8080
localhost:8080>
kubernetes redis kubernetes-helm minikube pulumi
1个回答
0
投票

我已经尝试过你的设置。您需要将

auth.enabled
设置为
False
以禁用 Redis Bitnami 图表的身份验证。

这是一个示例设置:

import pulumi
import pulumi_kubernetes as kubernetes

config = pulumi.Config()
k8s_namespace = config.get("k8sNamespace", "default")
app_labels = {
    "app": "redis-app",
}

# Create a namespace (user supplies the name of the namespace)
redis_ns = kubernetes.core.v1.Namespace(
    "redis",
    metadata=kubernetes.meta.v1.ObjectMetaArgs(
        labels=app_labels,
        name=k8s_namespace,
    )
)


# Use Helm to install the Redis chart
redis_chart = kubernetes.helm.v3.Release(
    "redis",
    chart="redis",
    namespace=redis_ns.metadata.name,
    repository_opts=kubernetes.helm.v3.RepositoryOptsArgs(
        repo="https://charts.bitnami.com/bitnami",
    ),
    skip_crds=True,
    # values={
    #     "usePassword": False
    # }
    values={
        "auth": {
            "enabled": False
        }
    }
)

# Export some values for use elsewhere
pulumi.export("name", redis_chart.name)

豆荚:

$ k get po -n redis                                                                                                                                                                                                
NAME                        READY   STATUS    RESTARTS   AGE
redis-69a473da-master-0     1/1     Running   0          6m12s
redis-69a473da-replicas-0   1/1     Running   0          6m12s
redis-69a473da-replicas-1   1/1     Running   0          5m35s
redis-69a473da-replicas-2   1/1     Running   0          5m13s

转发:

$ k port-forward -n redis redis-69a473da-master-0 8081:6379                                                                                                                                                       
Forwarding from 127.0.0.1:8081 -> 6379
Forwarding from [::1]:8081 -> 6379
Handling connection for 8081

Redis 命令行:

$ redis-cli -p 8081
127.0.0.1:8081> 

RedisInsight v2 添加:

当我将

usePassword
设置为
False
并且未通过
auth.enabled
时,我将启用启用身份验证的 Redis。

redis-cli 当 bitnami 图表使用

usePassword=False
而不是
auth.enabled=False
时:


$ redis-cli -p 8081                                                                                                                                                                                                
127.0.0.1:8081> KEYS *
(error) NOAUTH Authentication required.

关于最后的redis-cli连接,是否有任何命令成功,或者有任何协议错误?可能是 redis-cli 连接到 RedisInsight v2 的 8080 端口或使用 8080 tcp 端口的任何其他现有服务。

© www.soinside.com 2019 - 2024. All rights reserved.