Minikube将在本地主机上运行的MySQL作为服务公开 [英] Minikube expose MySQL running on localhost as service
问题描述
我的机器上正在运行minikube v0.17.1版.我想模拟AWS中的环境,我的MySQL实例将在Kubernetes集群之外.
I have minikube version v0.17.1 running on my machine. I want to simulate the environment I will have in AWS, where my MySQL instance will be outside of my Kubernetes cluster.
基本上,如何将我的计算机上运行的本地MySQL实例公开给通过minikube运行的Kubernetes集群?
Basically, how can I expose my local MySQL instance running on my machine to the Kubernetes cluster running via minikube?
推荐答案
Kubernetes允许您创建不带选择器的服务,并且群集不会为此服务创建相关端点,此功能通常用于代理旧版组件或代理.外部组件.
Kubernetes allows you to create a service without selector, and cluster will not create related endpoint for this service, this feature is usually used to proxy a legacy component or an outside component.
-
创建不带选择器的服务
Create a service without selector
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
ports:
- protocol: TCP
port: 1443
targetPort: <YOUR_MYSQL_PORT>
创建一个相对的Endpoint对象
Create a relative Endpoint object
apiVersion: v1
kind: Endpoints
metadata:
name: my-service
subsets:
- addresses:
- ip: <YOUR_MYSQL_ADDR>
ports:
- port: <YOUR_MYSQL_PORT>
获取服务IP
Get service IP
$ kubectl get svc my-service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-service <SERVICE_IP> <none> 1443/TCP 18m
从服务<SERVICE_IP>:1443
或my-service:1443
这篇关于Minikube将在本地主机上运行的MySQL作为服务公开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!