我试图在kubernetes上部署nginx, kubernetes版本是v1.5.2, 我已经部署了nginx的3个副本,YAML文件如下,

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: deployment-example
spec:
  replicas: 3
  revisionHistoryLimit: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.10
        ports:
        - containerPort: 80

现在我想在节点的30062端口上公开它的80端口,为此我在下面创建了一个服务,

kind: Service
apiVersion: v1
metadata:
  name: nginx-ils-service
spec:
  ports:
    - name: http
      port: 80
      nodePort: 30062
  selector:
    app: nginx
  type: LoadBalancer

这项服务工作得很好,但它不仅在kubernetes仪表板上也在终端上显示为待定。


当前回答

对于您的用例,最好的选择是使用NordPort服务而不是loadbalancer类型,因为loadbalancer不可用。

其他回答

如果您没有使用GCE或EKS(您使用的是kubeadm),您可以向您的服务YAML添加一个externalps规范。您可以使用与节点主接口相关联的IP,例如eth0。然后,您可以使用节点的外部IP从外部访问该服务。

...
spec:
  type: LoadBalancer
  externalIPs:
  - 192.168.0.10

我也有同样的问题。 Windows 10 Desktop + Docker Desktop 4.7.1 (77678) + Minikube v1.25.2

根据我这边的官方文件,我决定:

PS C:\WINDOWS\system32> kubectl expose deployment sito-php --type=LoadBalancer --port=8080 --name=servizio-php
service/servizio-php exposed
PS C:\WINDOWS\system32> minikube tunnel
 * Tunnel successfully started

 * NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ...

 * Starting tunnel for service servizio-php.


PS E:\docker\apache-php> kubectl get service
NAME           TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes     ClusterIP      10.96.0.1      <none>        443/TCP          33h
servizio-php   LoadBalancer   10.98.218.86   127.0.0.1     8080:30270/TCP   4m39s

http://127.0.0.1:8080/上的开放浏览器

检查kube-controller日志。我能够通过将clusterID标记设置为我部署集群的ec2实例来解决这个问题。

为在amazon-eks上运行时遇到此错误的用户添加解决方案。

首先运行:

kubectl describe svc <service-name>

然后查看下面示例输出中的events字段:

Name:                     some-service
Namespace:                default
Labels:                   <none>
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"some-service","namespace":"default"},"spec":{"ports":[{"port":80,...
Selector:                 app=some
Type:                     LoadBalancer
IP:                       10.100.91.19
Port:                     <unset>  80/TCP
TargetPort:               5000/TCP
NodePort:                 <unset>  31022/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type     Reason                  Age        From                Message
  ----     ------                  ----       ----                -------
  Normal   EnsuringLoadBalancer    68s  service-controller  Ensuring load balancer
  Warning  SyncLoadBalancerFailed  67s  service-controller  Error syncing load balancer: failed to ensure load balancer: could not find any suitable subnets for creating the ELB

查看错误消息:

Failed to ensure load balancer: could not find any suitable subnets for creating the ELB

在我的例子中,没有为创建ELB提供合适的子网的原因是:

原因1:EKS集群部署在错误的子网组中——内部子网,而不是公网子网。 (*)默认情况下,如果没有service.beta.kubernetes, LoadBalancer类型的服务将创建面向公共的负载均衡器。Io /aws-load-balancer-internal:“true”注释)。

2:子网没有按照这里提到的要求进行标记。

为VPC添加标签:

Key: kubernetes.io/cluster/yourEKSClusterName
Value: shared

用以下标记公共子网:

Key: kubernetes.io/role/elb
Value: 1

如果你正在使用Minikube,有一个神奇的命令!

$ minikube tunnel

希望有人能节省几分钟的时间。

参考链接 https://minikube.sigs.k8s.io/docs/handbook/accessing/#using-minikube-tunnel