我已经尝试过通过创建服务来提及的所有方法,但是仍然没有锁定。我坚持下去。所以我创建了一个没有选择器的服务,然后指向localhost mysql地址的端点仍然没有运气。我已经看过这篇文章https://stackoverflow.com/a/43477742/5821354。我想要的是一个连接到Mac上本地mysql数据库的服务,并通过提供环境变量使用该服务连接到作为部署运行的前端。
答案 0 :(得分:0)
我尝试了与您共享的链接相同的步骤,它对我有用。
首先,我在VM上安装了mysq-server并创建了一个数据库,并且用户app
拥有访问数据库的权限。
第二,应用服务和端点Yaml,并按如下所述与simples pod连接。
请注意,您不能使用
127.0.0.1
创建端点,而需要使用内部ip。
这是我的Yaml规格:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
ports:
- protocol: TCP
port: 1443
targetPort: 3306
---
apiVersion: v1
kind: Endpoints
metadata:
name: my-service
subsets:
- addresses:
- ip: 10.xx.xx.xx
ports:
- port: 3306
和一个用于测试连接的Pod:
kex alpine -- sh -c "apk update && apk add mysql-client"
注意::要通过Pod进行连接,您需要使用命令
输出中显示的IPkubectl get endpoint
$ kubectl exec alpine -- sh -c "mysql -h 10.xx.xx.xx -uapp -p123456"
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.1.45-MariaDB-0+deb9u1 Debian 9.12
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>