kubernetes中具有持久卷的redisinsights

qlvxas9a  于 2021-06-10  发布在  Redis
关注(0)|答案(3)|浏览(598)

我有以下几点 .yaml 要安装的文件 redisinsights 在kubernetes中,支持持久性。

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: redisinsight-storage-class
provisioner: 'kubernetes.io/gce-pd'
parameters:
  type: 'pd-standard'
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redisinsight-volume-claim
spec:
  storageClassName: redisinsight-storage-class
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redisinsight #deployment name
  labels:
    app: redisinsight #deployment label
spec:
  replicas: 1 #a single replica pod
  selector:
    matchLabels:
      app: redisinsight #which pods is the deployment managing, as defined by the pod template
  template: #pod template
    metadata:
      labels:
        app: redisinsight #label for pod/s
    spec:
      initContainers:
        - name: change-data-dir-ownership
          image: alpine:3.6
          command:
            - chmod
            - -R
            - '777'
            - /db
          volumeMounts:
            - name: redisinsight
              mountPath: /db
      containers:
        - name: redisinsight #Container name (DNS_LABEL, unique)
          image: redislabs/redisinsight:1.6.1 #repo/image
          imagePullPolicy: Always #Always pull image
          volumeMounts:
            - name: redisinsight #Pod volumes to mount into the container's filesystem. Cannot be updated.
              mountPath: /db
          ports:
            - containerPort: 8001 #exposed conainer port and protocol
              protocol: TCP
      volumes:
        - name: redisinsight
          persistentVolumeClaim:
            claimName: redisinsight-volume-claim
---
apiVersion: v1
kind: Service
metadata:
  name: redisinsight
spec:
  ports:
    - port: 8001
      name: redisinsight
  type: LoadBalancer
  selector:
    app: redisinsight

但是,它无法启动并给出一个错误:

INFO 2020-07-03 06:30:08,117 redisinsight_startup Registered SIGTERM handler
ERROR 2020-07-03 06:30:08,131 redisinsight_startup Error in main()
Traceback (most recent call last):
  File "./startup.py", line 477, in main
ValueError: invalid literal for int() with base 10: 'tcp://10.69.9.111:8001'
Traceback (most recent call last):
  File "./startup.py", line 495, in <module>
  File "./startup.py", line 477, in main
ValueError: invalid literal for int() with base 10: 'tcp://10.69.9.111:8001'

但通过docker本地运行时,相同的docker映像为:

docker run -v redisinsight:/db -p 8001:8001 redislabs/redisinsight

很好用。我做错什么了?
这感觉就像redisinsights试图将端口读取为int,但不知何故得到了一个字符串,并且感到困惑。但我不明白这是怎么运作的本地 Docker 运行良好。

abithluo

abithluo1#

这也发生在我身上。如果有人错过了评论中的对话,下面是解决方法。
首先部署redisinsight pod,并等待它成功运行。
部署服务。
我认为这是一个错误,它不是真的工作,因为一个豆荚可以随时死亡。这有点违背使用kubernetes的理由。
有人在这里报告了这个问题https://forum.redislabs.com/t/redisinsight-fails-to-launch-in-kubernetes/652/2

biswetbf

biswetbf2#

更新:
redisinsight的kubernetes文档最近进行了更新。它清楚地描述了如何创建一个redisinsight k8s部署,有服务和没有服务。
它还解释了当已经有一个名为“redisinsight”的服务时该怎么做:
注意-如果部署将由名为“redisinsight”的服务公开,请设置redisinsight\u host和redisinsight\u port环境变量以覆盖该服务创建的环境变量。
问题在于服务的名称。
文档中提到redisinsight有一个环境变量 REDISINSIGHT_PORT 它可以配置运行redisinsight的端口。
在kubernetes中创建服务时,所有与该服务匹配的pod都会获得一个环境变量 <SERVICE_NAME>_PORT=<SERVICE_IP>:<SERVICE_PORT> .
因此,当您尝试使用名称创建上述服务时 redisinsight ,kubernetes传递服务环境变量 REDISINSIGHT_PORT=<SERVICE_IP>:SERVICE_PORT . 但是端口环境变量( REDISINSIGHT_PORT )在pod上运行的redisinsight尝试使用环境变量作为端口号时,记录为端口号,而不是使pod崩溃的端点。
因此,将服务的名称更改为不同的名称,而不是 redisinsight 它应该有用。
下面是一个快速部署和服务文件:
部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redisinsight #deployment name
  labels:
    app: redisinsight #deployment label
spec:
  replicas: 1 #a single replica pod
  selector:
    matchLabels:
      app: redisinsight #which pods is the deployment managing, as defined by the pod template
  template: #pod template
    metadata:
      labels:
        app: redisinsight #label for pod/s
    spec:
      containers:
      - name:  redisinsight #Container name (DNS_LABEL, unique)
        image: redislabs/redisinsight:1.6.3 #repo/image
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: db #Pod volumes to mount into the container's filesystem. Cannot be updated.
          mountPath: /db
        ports:
        - containerPort: 8001 #exposed conainer port and protocol
          protocol: TCP
      volumes:
      - name: db
        emptyDir: {} # node-ephemeral volume https://kubernetes.io/docs/concepts/storage/volumes/#emptydir

服务:

apiVersion: v1
kind: Service
metadata:
  name: redisinsight-http # name should not be redisinsight 
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8001
  selector:
    app: redisinsight

请注意服务的名称。
redisinsight吊舱日志:

INFO 2020-09-02 11:46:20,689 redisinsight_startup Registered SIGTERM handler
 INFO 2020-09-02 11:46:20,689 redisinsight_startup Starting webserver...
 INFO 2020-09-02 11:46:20,689 redisinsight_startup Visit http://0.0.0.0:8001 in your web browser. Press CTRL-C to exit.

还有服务端点(从minikube):

$ minikube service list                                                                              
|----------------------|------------------------------------|--------------|-------------------------|
|      NAMESPACE       |                NAME                | TARGET PORT  |           URL           |
|----------------------|------------------------------------|--------------|-------------------------|
| default              | kubernetes                         | No node port |
| default              | redisinsight-http                  |           80 | http://172.17.0.2:30860 |
| kube-system          | ingress-nginx-controller-admission | No node port |
| kube-system          | kube-dns                           | No node port |
| kubernetes-dashboard | dashboard-metrics-scraper          | No node port |
| kubernetes-dashboard | kubernetes-dashboard               | No node port |
|----------------------|------------------------------------|--------------|-------------------------|

顺便说一句,如果您根本不想创建服务(这与问题无关),您可以执行端口转发:

kubectl port-forward <redisinsight-pod-name> 8001:8001
mzillmmw

mzillmmw3#

问题与服务有关,因为它干扰了 pod 导致它崩溃。
正如我们在redis文档中看到的,在kubernetes上安装redisinsight
成功应用部署并完成部署后,请访问redisinsight。这可以通过将部署公开为k8s服务或使用端口转发来实现,如下例所示: kubectl port-forward deployment/redisinsight 8001 打开浏览器并指向http://localhost:8001
或者在您使用gcp的情况下,服务可以如下所示:

apiVersion: v1
kind: Service
metadata:
  name: redisinsight
spec:
  ports:
    - protocol: TCP
      port: 8001
      targetPort: 8001
      name: redisinsight
  type: LoadBalancer
  selector:
    app: redisinsight

一旦服务接收到外部ip,您就可以使用它来访问redis。

crou@cloudshell:~ $ kubectl get service
NAME           TYPE           CLUSTER-IP   EXTERNAL-IP     PORT(S)          AGE
kubernetes     ClusterIP      10.8.0.1     <none>          443/TCP          9d
redisinsight   LoadBalancer   10.8.7.0     34.67.171.112   8001:31456/TCP   92s

通过http://34.67.171.112:8001/在我的例子中。

相关问题