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

xesrikrc  于 5个月前  发布在  Kubernetes
关注(0)|答案(1)|浏览(55)

**已关闭。**此问题为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文件

# Mysql server deployment config
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql:8.0.35
          ports:
            - containerPort: 3306
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: mysql-config-map
                  key: mysql-root-pwd
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: mysql
                  key: MYSQL_USER
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql
                  key: MYSQL_PWD
            # - name: MYSQL_DATA
            #   value: /var/opt/mysql/data/mysqldata
          volumeMounts:
            - name: mysqldb
              mountPath: /var/opt/mysql/data
      volumes:
        - name: mysqldb
          persistentVolumeClaim:
            claimName: mysql-pvc

# Cluster IP config
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-clusterip-srv
spec:
  type: ClusterIP
  selector:
  # 'mysql-deploy' app pointer
    app: mysql
  ports:
    - name: mysql
      protocol: TCP
      port: 3306
      targetPort: 3306

# Loadbalancer config - allows direct access to mysql server
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-loadbalancer-srv
spec:
  type: LoadBalancer
  selector:
  # 'mysql-deploy' app pointer
    app: mysql
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306

字符串

MySQL日志

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.
2023-11-20 14:58:50 2023-11-20 09:28:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
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.
2023-11-20 14:58:50 2023-11-20 09:28:50+00:00 [Note] [Entrypoint]: Initializing database files
2023-11-20 15:02:11 2023-11-20 09:32:11+00:00 [Note] [Entrypoint]: Database files initialized
2023-11-20 15:02:11 2023-11-20 09:32:11+00:00 [Note] [Entrypoint]: Starting temporary server
2023-11-20 15:02:25 2023-11-20 09:32:25+00:00 [Note] [Entrypoint]: Temporary server started.
2023-11-20 15:02:25 '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2023-11-20 15:02:46 2023-11-20 09:32:46+00:00 [Note] [Entrypoint]: Creating user nawaz
2023-11-20 15:02:47 
2023-11-20 15:02:47 2023-11-20 09:32:47+00:00 [Note] [Entrypoint]: Stopping temporary server
2023-11-20 15:03:20 2023-11-20 09:33:20+00:00 [Note] [Entrypoint]: Temporary server stopped
2023-11-20 15:03:20 
2023-11-20 15:03:20 2023-11-20 09:33:20+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2023-11-20 15:03:20 
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.
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
2023-11-20 14:58:51 2023-11-20T09:28:51.014934Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-11-20 14:59:13 2023-11-20T09:29:13.382504Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
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.
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.
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
2023-11-20 15:02:11 2023-11-20T09:32:11.837713Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-11-20 15:02:18 2023-11-20T09:32:18.174741Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-11-20 15:02:25 2023-11-20T09:32:25.306013Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
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.
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.
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
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.
2023-11-20 15:02:36 Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
2023-11-20 15:02:36 Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
2023-11-20 15:02:36 Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
2023-11-20 15:02:43 Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
2023-11-20 15:02:43 Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
2023-11-20 15:02:43 Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
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).
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.
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.
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
2023-11-20 15:03:20 2023-11-20T09:33:20.428757Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-11-20 15:03:22 2023-11-20T09:33:22.741252Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-11-20 15:03:27 2023-11-20T09:33:27.884744Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
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.
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.
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
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.

负载均衡服务

NAME                     TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes               ClusterIP      10.96.0.1       <none>        443/TCP          4h13m
mysql-clusterip-srv      ClusterIP      10.101.179.4    <none>        3306/TCP         9m17s
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不是一个选项,那么就进行上面的安装。否则,端口转发就足以连接到主机上运行的数据库客户端。

相关问题