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

ao218c7q  于 2023-10-15  发布在  Redis
关注(0)|答案(1)|浏览(228)

所以我用HelmChartBitnami在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无密码x1c 0d1x
在那之后,我直接在我的minikube中部署了redisinsight,并尝试用第一个yaml将其连接到内部主机https://docs.redis.com/latest/ri/installing/install-k8s/

这里是我的脚本pulumi-python,我在其中声明了redis数据库的helm chart部署:

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])
)

usePasswordfalse我不应该有任何密码设置进一步在我的终端当我试图连接到数据库与redis-cli命令它似乎工作

redis-cli -h localhost -p 8080
localhost:8080>
azpvetkf

azpvetkf1#

我试过你的设置。您需要将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 cli:

$ redis-cli -p 8081
127.0.0.1:8081>

RedisInsight v2新增功能:

当我将usePassword设置为False并且不传递auth.enabled时,我得到了启用了身份验证的redis。
当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端口的现有服务。

相关问题