我试图在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仪表板上也在终端上显示为待定。


当前回答

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

其他回答

同样的问题:

os>kubectl get svc right-sabertooth-wordpress NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) right-sabertooth-wordpress LoadBalancer 10.97.130.7 "pending" 80:30454/TCP,443:30427/TCP os>minikube service list |-------------|----------------------------|--------------------------------| | NAMESPACE | NAME | URL | |-------------|----------------------------|--------------------------------| | default | kubernetes | No node port | | default | right-sabertooth-mariadb | No node port | | default | right-sabertooth-wordpress | http://192.168.99.100:30454 | | | | http://192.168.99.100:30427 | | kube-system | kube-dns | No node port | | kube-system | tiller-deploy | No node port | |-------------|----------------------------|--------------------------------|

但是,可以通过http://192.168.99.100:30454访问。

为在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

删除所有旧的服务并创建新的服务解决了我的问题。IP被绑定到旧的服务。只需尝试“$kubectl获得svc”,然后逐个删除所有svc的“$kubectl删除svc' svc名称”

如果你不在一个受支持的云上(aws, azure, gcloud等),你不能在没有MetalLB的情况下使用LoadBalancer https://metallb.universe.tf/ 但它还在测试阶段。