問題描述
我在我的 centos 機器上運行一個 kubernetes 集群.我不想為 mysql 創(chuàng)建一個 pod.MySQL安裝在同一網(wǎng)絡(luò)的另一臺機器上(機器不在kubernates私有網(wǎng)絡(luò)中).
I am running a kubernetes cluster in my centos machine. I donot want to create a pod for mysql. MySQL is installed in another machine in same network (Machine is not in kubernates private network).
如何從運行在 kubernetes 集群中的 pod 訪問 mysql 服務(wù)?
How can I access the mysql service from the pods running in kubernetes cluster ?
我已嘗試使用以下配置的服務(wù)和端點.但是,運氣不好.
I have tried with service and end point with below configuration. But, No luck.
apiVersion: v1
kind: Service
metadata:
name: database
spec:
ports:
- port: 13080
targetPort: 13080
protocol: TCP
---
kind: Deployment
apiVersion: v1
metadata:
name: database
subsets:
- addresses:
- ip: XX.XX.XX.XX
ports:
- port: 13080
---
kind: ReplicationController
metadata:
name: test
spec:
replicas: 1
selector:
app: test
template:
metadata:
name: test
labels:
app: test
spec:
containers:
- name: my_pods
image: my_pods
env:
- name: DATABASE_HOST
value: database
- name: DATABASE_PORT
value: "13080"
- name: DATABASE_USER
value: "SAAS"
- name: DATABASE_PASSWORD
value: "SAAS"
- name: DATABASE_NAME
value: "SAASDB"
ports:
- containerPort: 8080
imagePullSecrets:
- name: my-secret
---
apiVersion: v1
kind: Service
metadata:
name: test-service
labels:
name: test-service
spec:
type: NodePort
ports:
- port: 11544
targetPort: 8080
nodePort: 30600
selector:
name: test
推薦答案
對于集群外的事物,您不需要服務(wù).根據(jù)您使用的網(wǎng)絡(luò)模型,docker 容器(即 kubernetes pod)應(yīng)該能夠通過 Docker 設(shè)置的網(wǎng)橋正常連接到 MySQL 容器.檢查主機在端口 3306 上是否具有連接性,并且確實如此,只需輸入 DNS 名稱(您的 kube-dns pod 應(yīng)該將任何基于非 kubernetes 的請求轉(zhuǎn)發(fā)到它被調(diào)度到的主機的主機 resolv.conf)
You don't need a service for things outside the cluster. Depending on the networking model you're using, the docker container (ie kubernetes pod) should be able to connect to the MySQL container normally via the bridge that Docker sets up. Check the host has connectivity on port 3306, and it does, simply put in the DNS name (your kube-dns pod should forward any non kubernetes based requests on to the hosts resolv.conf of the host it was scheduled on)
這篇關(guān)于如何在我的 kubernetes 集群外訪問 mysql?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!