我现在在kubernetes集群v1.18中使用traefik 2.2.1,现在我想从kubernetes集群中暴露mysql端口,然后跟随官方doc,添加启动参数:
- '--entryPoints.tcpep.address=:3308'
并添加端口定义:
ports:
- name: tcpep
hostPort: 3308
containerPort: 3308
protocol: TCP
这是tcp入口路由:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: report-mysql
spec:
entryPoints:
- tcpep
routes:
- match: HostSNI(`*`)
services:
- name: report-mysqlha
port: 3306
然后检查主机中侦听的端口:
[dolphiin@K8SSlave3 production]$ sudo lsof -i:3308
[sudo] password for miaoyou:
lsof: no pwd entry for UID 65532
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
lsof: no pwd entry for UID 65532
traefik 28956 65532 8u IPv6 2902156338 0t0 TCP *:tns-server (LISTEN)
扫描端口:
[dolphin@K8SSlave3 production]$ sudo nmap -sS -p 3308 -v 192.168.64.251
Starting Nmap 6.40 ( http://nmap.org ) at 2020-08-28 19:19 CST
Initiating SYN Stealth Scan at 19:19
Scanning MeowK8SSlave3 (192.168.64.251) [1 port]
Discovered open port 3308/tcp on 192.168.64.251
Completed SYN Stealth Scan at 19:19, 0.21s elapsed (1 total ports)
Nmap scan report for MeowK8SSlave3 (192.168.64.251)
Host is up (0.000071s latency).
PORT STATE SERVICE
3308/tcp open unknown
但是当我登录MySQL时:
mycli -h 192.168.64.251 -P 3308 -u root -p OgHeee8bfw6jcadewu
它卡住了,没有响应,映射端口成功了吗?为什么我无法登录mysql? PS:当我使用kubernetes服务ip登录时,它可以成功登录。
我尝试过的事情:
当我访问traefik仪表板时发现,它给了我一些提示(名称不同,因为我在家用计算机的不同kubernetes集群中进行尝试):
the service "infrastructure-mysql-673acf455cb2dab0b43a@kubernetescrd" does not exist
,我发现traefik仪表板没有TCP服务。我正在尝试创建这样的TraefikService:
[root@k8smaster traefik]# cat mysql-tcp-services.yaml
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
name: mysql-service
spec:
tcp:
services:
mysql:
loadBalancer:
servers:
- address: "10.20.58.239:3306"
似乎不起作用。仪表板仍未找到TCP服务,该怎么办?
答案 0 :(得分:0)
config IngressRouteTCP像这样:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: report-mysql
spec:
entryPoints:
- tcpep
routes:
- match: HostSNI(`*`)
services:
- name: report-mysqlha
port: 3306
有效。