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>
创建一个相对端点对象
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
从服务
或 my-service:1443
这篇关于Minikube 将在本地主机上运行的 MySQL 作为服务公开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!