Web Services 无法通过Web浏览器通过外部IP连接到Kubernetes服务

bkhjykvo  于 2022-11-15  发布在  Kubernetes
关注(0)|答案(1)|浏览(229)

我在Kubernetes上使用minikube,在我的应用程序上使用Docker和VirtualBox。
我已经为MySQL数据库和phpmyadmin创建了几个服务+部署。它们都是绿色的,表示没有问题:

但是,当我点击phpmyadmin-service的外部端点时,我的浏览器拒绝连接:

以下是我的metallb配置和minikube ip输出,以防万一:

我的服务和部署的yaml清单文件确实包含正确的端口:

apiVersion: v1
kind: Service
metadata:
  name: phpmyadmin-service
  labels:
    app: phpmyadmin
  annotations:
    metallb.universe.tf/allow-shared-ip: shared
spec:
  type: LoadBalancer
  ports:
  - port: 5000
    targetPort: 5000
  selector:
    app: phpmyadmin
---
apiVersion: apps/v1 
kind: Deployment
metadata:
  name: phpmyadmin-deployment
  labels:
    app: phpmyadmin
spec:
  selector:
    matchLabels:
      app: phpmyadmin
  replicas: 1
  template:
    metadata:
      labels:
        app: phpmyadmin
    spec:
      restartPolicy: Always
      containers:
      - name: phpmyadmin
        image: phpmyadmin
        imagePullPolicy: Never
        ports:
        - containerPort: 5000

知道怎么回事吗?
UPD:kubectl get svc的输出:

c1r10s2% kubectl get svc
NAME                 TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
kubernetes           ClusterIP      10.96.0.1       <none>           443/TCP          2m54s
mysql-service        ClusterIP      10.109.243.20   <none>           3306/TCP         73s
phpmyadmin-service   LoadBalancer   10.103.233.51   192.168.99.100   5000:30348/TCP   73s

kubect describe svc的输出:

c1r10s2% kubectl describe svc
Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
                   provider=kubernetes
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP Families:       <none>
IP:                10.96.0.1
IPs:               10.96.0.1
Port:              https  443/TCP
TargetPort:        8443/TCP
Endpoints:         192.168.99.100:8443
Session Affinity:  None
Events:            <none>

Name:              mysql-service
Namespace:         default
Labels:            app=mysql
Annotations:       <none>
Selector:          app=mysql
Type:              ClusterIP
IP Families:       <none>
IP:                10.109.243.20
IPs:               10.109.243.20
Port:              <unset>  3306/TCP
TargetPort:        3306/TCP
Endpoints:         172.17.0.8:3306
Session Affinity:  None
Events:            <none>

Name:                     phpmyadmin-service
Namespace:                default
Labels:                   app=phpmyadmin
Annotations:              metallb.universe.tf/allow-shared-ip: shared
Selector:                 app=phpmyadmin
Type:                     LoadBalancer
IP Families:              <none>
IP:                       10.103.233.51
IPs:                      10.103.233.51
LoadBalancer Ingress:     192.168.99.100
Port:                     <unset>  5000/TCP
TargetPort:               5000/TCP
NodePort:                 <unset>  30348/TCP
Endpoints:                172.17.0.2:5000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason        Age   From                Message
  ----    ------        ----  ----                -------
  Normal  IPAllocated   2m1s  metallb-controller  Assigned IP "192.168.99.100"
  Normal  nodeAssigned  119s  metallb-speaker     announcing from node "minikube"
jdzmm42g

jdzmm42g1#

我看到您正在使用MetalLB。问题是,可能没有一个规则来管理到负载平衡器端点的连接。您可以检查以下事项:

  • 您的群集是否启用了内部路由?通过在BGP中使用MetalLB,您将需要路由重新分配(BGP网关,以便可以了解10.130.x.x网络和192.168.x.x网络之间的路由)
  • 如果您在Layer-2中运行,那么您需要在您的kubelet服务中启用StrictARP(如果您使用Calico进行集群联网,那么在BGP模式中也需要启用StrictARP。原因很复杂,但您可以调查)
  • 使用IPVS而不是Iptables。MetalLB需要IPVS
  • PhpMyadmin还需要环境变量才能访问mysql。因此,您需要在部署中传递PMA_HOST和PMA_PORT以及密码env。如下所示:
apiVersion: apps/v1 
kind: Deployment
metadata:
  name: phpmyadmin-deployment
  labels:
    app: phpmyadmin
spec:
  selector:
    matchLabels:
      app: phpmyadmin
  replicas: 1
  template:
    metadata:
      labels:
        app: phpmyadmin
    spec:
      restartPolicy: Always
      containers:
      - name: phpmyadmin
        image: phpmyadmin
        imagePullPolicy: Never
        ports:
        - containerPort: 5000
        env:                             
        - name: PMA_HOST               
          value: mysql-service # this is a reference to the mysql service                
        - name: PMA_PORT               
          value: "3306"                
        - name: MYSQL_ROOT_PASSWORD    
          valueFrom:                   
            secretKeyRef:              
              name: mysql-secret # This is your mysql secret from the file example below             
              key: mysql-root-password

您需要在mysql部署的secrets文件中预先启用secrets,并在其中提供加密的凭据。

apiVersion: v1        
 kind: Secret          
 metadata:             
   name: mysql-secret         
   namespace: namespace      
   labels:             
     app: mysql-service # the label of your mysql deployment        
 type: Opaque          
 data:                        
   mysql-root-password:   # base64 encoded passwords here              
   mysql-password:

相关问题