kubernetes on docker loadbalancer service external ip pending - ubuntu [已关闭]

xesrikrc  于 2024-01-07  发布在  Kubernetes
关注(0)|答案(1)|浏览(167)

**已关闭。**此问题为not about programming or software development。目前不接受回答。

此问题似乎与a specific programming problem, a software algorithm, or software tools primarily used by programmers无关。如果您认为此问题与another Stack Exchange site的主题相关,可以发表评论,说明在何处可以回答此问题。
上个月关门了。
Improve this question
我正在尝试为Spring Boot 项目在K8S集群中启动MySQL服务器。K8S运行在Docker桌面上。为了在本地访问DB,我已经设置了一个负载均衡器服务。当DB服务器ups我的负载均衡器服务外部IP卡在挂起状态。我已经做了一个类似的事情点-net项目早些时候在windows OS K8S上docker没有问题,我得到了外部IP作为localhost的sql server安装.我已经附上了相关的代码.帮助将不胜感激.谢谢.

yaml文件

  1. # Mysql server deployment config
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: mysql-deploy
  6. spec:
  7. replicas: 1
  8. selector:
  9. matchLabels:
  10. app: mysql
  11. template:
  12. metadata:
  13. labels:
  14. app: mysql
  15. spec:
  16. containers:
  17. - name: mysql
  18. image: mysql:8.0.35
  19. ports:
  20. - containerPort: 3306
  21. env:
  22. - name: MYSQL_ROOT_PASSWORD
  23. valueFrom:
  24. configMapKeyRef:
  25. name: mysql-config-map
  26. key: mysql-root-pwd
  27. - name: MYSQL_USER
  28. valueFrom:
  29. secretKeyRef:
  30. name: mysql
  31. key: MYSQL_USER
  32. - name: MYSQL_PASSWORD
  33. valueFrom:
  34. secretKeyRef:
  35. name: mysql
  36. key: MYSQL_PWD
  37. # - name: MYSQL_DATA
  38. # value: /var/opt/mysql/data/mysqldata
  39. volumeMounts:
  40. - name: mysqldb
  41. mountPath: /var/opt/mysql/data
  42. volumes:
  43. - name: mysqldb
  44. persistentVolumeClaim:
  45. claimName: mysql-pvc
  46. # Cluster IP config
  47. ---
  48. apiVersion: v1
  49. kind: Service
  50. metadata:
  51. name: mysql-clusterip-srv
  52. spec:
  53. type: ClusterIP
  54. selector:
  55. # 'mysql-deploy' app pointer
  56. app: mysql
  57. ports:
  58. - name: mysql
  59. protocol: TCP
  60. port: 3306
  61. targetPort: 3306
  62. # Loadbalancer config - allows direct access to mysql server
  63. ---
  64. apiVersion: v1
  65. kind: Service
  66. metadata:
  67. name: mysql-loadbalancer-srv
  68. spec:
  69. type: LoadBalancer
  70. selector:
  71. # 'mysql-deploy' app pointer
  72. app: mysql
  73. ports:
  74. - protocol: TCP
  75. port: 3306
  76. targetPort: 3306

字符串

MySQL日志

  1. 2023-11-20 14:58:50 2023-11-20 09:28:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.35-1.el8 started.
  2. 2023-11-20 14:58:50 2023-11-20 09:28:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
  3. 2023-11-20 14:58:50 2023-11-20 09:28:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.35-1.el8 started.
  4. 2023-11-20 14:58:50 2023-11-20 09:28:50+00:00 [Note] [Entrypoint]: Initializing database files
  5. 2023-11-20 15:02:11 2023-11-20 09:32:11+00:00 [Note] [Entrypoint]: Database files initialized
  6. 2023-11-20 15:02:11 2023-11-20 09:32:11+00:00 [Note] [Entrypoint]: Starting temporary server
  7. 2023-11-20 15:02:25 2023-11-20 09:32:25+00:00 [Note] [Entrypoint]: Temporary server started.
  8. 2023-11-20 15:02:25 '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
  9. 2023-11-20 15:02:46 2023-11-20 09:32:46+00:00 [Note] [Entrypoint]: Creating user nawaz
  10. 2023-11-20 15:02:47
  11. 2023-11-20 15:02:47 2023-11-20 09:32:47+00:00 [Note] [Entrypoint]: Stopping temporary server
  12. 2023-11-20 15:03:20 2023-11-20 09:33:20+00:00 [Note] [Entrypoint]: Temporary server stopped
  13. 2023-11-20 15:03:20
  14. 2023-11-20 15:03:20 2023-11-20 09:33:20+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
  15. 2023-11-20 15:03:20
  16. 2023-11-20 14:58:50 2023-11-20T09:28:50.779763Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
  17. 2023-11-20 14:58:50 2023-11-20T09:28:50.780163Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.35) initializing of server in progress as process 80
  18. 2023-11-20 14:58:51 2023-11-20T09:28:51.014934Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  19. 2023-11-20 14:59:13 2023-11-20T09:29:13.382504Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  20. 2023-11-20 15:00:15 2023-11-20T09:30:15.050008Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
  21. 2023-11-20 15:02:11 2023-11-20T09:32:11.565150Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
  22. 2023-11-20 15:02:11 2023-11-20T09:32:11.567401Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.35) starting as process 124
  23. 2023-11-20 15:02:11 2023-11-20T09:32:11.837713Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  24. 2023-11-20 15:02:18 2023-11-20T09:32:18.174741Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  25. 2023-11-20 15:02:25 2023-11-20T09:32:25.306013Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
  26. 2023-11-20 15:02:25 2023-11-20T09:32:25.306139Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
  27. 2023-11-20 15:02:25 2023-11-20T09:32:25.476643Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
  28. 2023-11-20 15:02:25 2023-11-20T09:32:25.567374Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
  29. 2023-11-20 15:02:25 2023-11-20T09:32:25.567569Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.35' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
  30. 2023-11-20 15:02:36 Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
  31. 2023-11-20 15:02:36 Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
  32. 2023-11-20 15:02:36 Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
  33. 2023-11-20 15:02:43 Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
  34. 2023-11-20 15:02:43 Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
  35. 2023-11-20 15:02:43 Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
  36. 2023-11-20 15:02:47 2023-11-20T09:32:47.069535Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.35).
  37. 2023-11-20 15:03:19 2023-11-20T09:33:19.629680Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.35) MySQL Community Server - GPL.
  38. 2023-11-20 15:03:20 2023-11-20T09:33:20.416167Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
  39. 2023-11-20 15:03:20 2023-11-20T09:33:20.418206Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.35) starting as process 1
  40. 2023-11-20 15:03:20 2023-11-20T09:33:20.428757Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  41. 2023-11-20 15:03:22 2023-11-20T09:33:22.741252Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  42. 2023-11-20 15:03:27 2023-11-20T09:33:27.884744Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
  43. 2023-11-20 15:03:27 2023-11-20T09:33:27.884810Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
  44. 2023-11-20 15:03:27 2023-11-20T09:33:27.983553Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
  45. 2023-11-20 15:03:28 2023-11-20T09:33:28.021454Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
  46. 2023-11-20 15:03:28 2023-11-20T09:33:28.022030Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.35' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.

负载均衡服务

  1. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  2. kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h13m
  3. mysql-clusterip-srv ClusterIP 10.101.179.4 <none> 3306/TCP 9m17s
  4. mysql-loadbalancer-srv LoadBalancer 10.108.170.58 <pending> 3306:31362/TCP 9m16s

esbemjvw

esbemjvw1#

在公共云提供商环境中,会调配外部负载均衡器,并将其公共IP地址分配给您的服务,并且自动执行将流量从负载均衡器定向到群集节点所需的网络配置。
问题是您的本地kubernetes集群没有为LoadBalancer类型的服务分配IP地址的机制。如果您确实想要LoadBalancer IP,可以使用MetalLB的L2模式安装。您需要设置合适的IPAddressPool配置。MetalLB的kind安装步骤与docker桌面相同。
如果你在linux机器上,你应该能够直接从主机ping IP,因为主机网络和Docker网络是连通的。

注意

如果kubectl port-forward不是一个选项,那么就进行上面的安装。否则,端口转发就足以连接到主机上运行的数据库客户端。

相关问题