在AWS-EKS上无法访问Kubernetes服务

时间:2018-10-03 07:34:34

标签: amazon-web-services kubernetes aws-load-balancer amazon-eks

我按照https://github.com/terraform-providers/terraform-provider-aws/tree/master/examples/eks-getting-started中的描述在aws上创建了一个简单的 EKS 集群。

在此集群中,我创建了 nginx部署和类型为 Loadbalancer 服务,如下所述。 该配置在minikube上本地工作。

在AWS上,我看到启动了pod和服务,该服务具有一个外部ip,我可以使用kubectl port-forward访问pod,并且可以ping LoadBalancer。

但是我无法通过浏览器通过http://a53439687c6d511e8837b02b7cab13e7-935938560.eu-west-1.elb.amazonaws.com:3001访问负载均衡器
我收到This site can’t be reached

知道我应该去哪里看看吗?

NGinx部署

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  labels:
    run: nginx
  name: nginx
  namespace: default
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      run: nginx
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        ports:
          - containerPort: 80
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30

NGinx服务

{
   "kind":"Service",
   "apiVersion":"v1",
   "metadata":{
      "name":"nginx",
      "labels":{
         "app":"nginx"
      }
   },
   "spec":{
      "ports": [
         {
           "port":3001,
           "targetPort":80
         }
      ],
      "selector":{
         "run":"nginx"
      },
      "type": "LoadBalancer"
   }
}

检查

kubectl get svc
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP                                                              PORT(S)          AGE
kubernetes   ClusterIP      172.20.0.1      <none>                                                                   443/TCP          1h
nginx        LoadBalancer   172.20.48.112   a53439687c6d511e8837b02b7cab13e7-935938560.eu-west-1.elb.amazonaws.com   3001:31468/TCP   45m

kubectl get pod
NAME                     READY     STATUS    RESTARTS   AGE
nginx-768979984b-vqz94   1/1       Running   0          49m

kubectl port-forward pod/nginx-768979984b-vqz94 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80

ping a53439687c6d511e8837b02b7cab13e7-935938560.eu-west-1.elb.amazonaws.com
PING a53439687c6d511e8837b02b7cab13e7-935938560.eu-west-1.elb.amazonaws.com (62.138.238.45) 56(84) bytes of data.
64 bytes from 62.138.238.45 (62.138.238.45): icmp_seq=1 ttl=250 time=7.21 ms

服务说明

Name:                     nginx
Namespace:                default
Labels:                   app=nginx
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"nginx"},"name":"nginx","namespace":"default"},"spec":{"ports":[{"port...
Selector:                 run=nginx
Type:                     LoadBalancer
IP:                       172.20.48.112
LoadBalancer Ingress:     a53439687c6d511e8837b02b7cab13e7-935938560.eu-west-1.elb.amazonaws.com
Port:                     <unset>  3001/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  31468/TCP
Endpoints:                10.0.0.181:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  EnsuringLoadBalancer  57m   service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   57m   service-controller  Ensured load balancer

1 个答案:

答案 0 :(得分:0)

请尝试以下3个步骤:

  1. 再次检查在服务和部署之间是否正确设置了选择器和标签。

  2. 在AWS内,转到已创建的负载均衡器(可能是经典)的“ 实例”选项卡,然后检查状态健康与LB相关的所有实例的状态:

enter image description here

如果状态不是“ InService”或状态不是“健康”-检查这些实例的安全组:
NodePort(在您的情况下为31468)应打开接受流量。

  1. 使用kubectl logs <pod-name>查看pod日志。