Kubernetes
K8S Redis 連接
我已經為 HA Redis 安裝了 Bitnami Helm Chart: https ://bitnami.com/stack/redis/helm
aleg@Azure:~$ kubectl get pods | grep redis redis-1580896952-master-0 1/1 Running 0 67m redis-1580896952-slave-0 1/1 Running 0 67m redis-1580896952-slave-1 1/1 Running 0 65m aleg@Azure:~$ kubectl get svc | grep redis redis-1580896952-headless ClusterIP None <none> 6379/TCP 67m redis-1580896952-master ClusterIP 10.0.244.169 <none> 6379/TCP 67m redis-1580896952-slave ClusterIP 10.0.250.136 <none> 6379/TCP 67m
我應該如何連接它?服務或主控吊艙或其他什麼?請指教。
範例:使用 Redis 部署 PHP 留言板應用程序很好地解釋了這一點。
解釋了整個設置過程,然後設置和公開留言簿前端描述瞭如何公開服務於 HTTP 請求的 Web 前端。它被配置為連接到
redis-master
寫入請求的redis-slave
服務和讀取請求的服務。範例
deployment
如下所示:apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 kind: Deployment metadata: name: frontend labels: app: guestbook spec: selector: matchLabels: app: guestbook tier: frontend replicas: 3 template: metadata: labels: app: guestbook tier: frontend spec: containers: - name: php-redis image: gcr.io/google-samples/gb-frontend:v4 resources: requests: cpu: 100m memory: 100Mi env: - name: GET_HOSTS_FROM value: dns # Using `GET_HOSTS_FROM=dns` requires your cluster to # provide a dns service. As of Kubernetes 1.3, DNS is a built-in # service launched automatically. However, if the cluster you are using # does not have a built-in DNS service, you can instead # access an environment variable to find the master # service's host. To do so, comment out the 'value: dns' line above, and # uncomment the line below: # value: env ports: - containerPort: 80
使用該設置,您只需要創建前端服務:
apiVersion: v1 kind: Service metadata: name: frontend labels: app: guestbook tier: frontend spec: # comment or delete the following line if you want to use a LoadBalancer type: NodePort # if your cluster supports it, uncomment the following to automatically create # an external load-balanced IP for the frontend service. # type: LoadBalancer ports: - port: 80 selector: app: guestbook tier: frontend
我建議閱讀有關Redis的文件。