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


当前回答

我也有同样的问题。 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/上的开放浏览器

其他回答

如果你正在使用minikube,那么从终端运行下面的命令,

$ minikube ip
$ 172.17.0.2 // then 
$ curl http://172.17.0.2:31245
or simply
$ curl http://$(minikube ip):31245

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

$ minikube tunnel

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

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

您可以修补pod托管的节点的IP(节点的私有IP),这是简单的解决方案。

参考上述职位,以下对我来说很有用:

Kubectl补丁服务my-loadbalancer-service-name \ -n lb-service-namespace \ - p '{"规范":{“类型”:“loadbalance”、“externalIPs”:[" xxx.xxx.xxx。xxx物理服务器私有IP -节点-部署位置"]}}'

使用NodePort:

$ kubectl run user-login --replicas=2 --labels="run=user-login" --image=kingslayerr/teamproject:version2  --port=5000

$ kubectl expose deployment user-login --type=NodePort --name=user-login-service

$ kubectl describe services user-login-service

(请记下端口)

$ kubectl cluster-info

获取主机正在运行的IP地址

您的服务可在(IP):(端口)访问

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