我已经尝试了上面提到的每种方法,甚至创建了服务,但仍然没有锁。我被同样的东西卡住了。因此,我创建了一个没有选择器的服务,然后端点指向localhost mysql地址,仍然没有成功。我已经看过这个帖子了,https://stackoverflow.com/a/43477742/5821354。所有我想要的是一个连接到mac上的本地mysql数据库的服务,并使用该服务通过提供环境变量来连接到作为部署运行的前端。
发布于 2020-08-14 20:54:57
我已经尝试了你分享的链接中的相同步骤,它对我有效。
首先,我在VM上安装了mysq-server,并创建了一个数据库和具有访问数据库权限的用户app。
其次,应用服务和端点yamls,并使用下面提到的简单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连接,您需要使用命令
kubectl get endpoint输出中显示的IP
$ 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)]> https://stackoverflow.com/questions/63406656
复制相似问题