简体   繁体   中英

kubernetes: AWS ELB not working

I have set up a front-end service via the following svc and deployment:

Deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: ui-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        els-pod: ui
    spec:
      containers:
      - image: pkaramol/the-ui
        name: ui
        ports:
        - containerPort: 80
      restartPolicy: Always

Service

apiVersion: v1
kind: Service
metadata:
  name: ui
spec:
  ports:
  - name: ui-port
    port: 8080
    targetPort: 80
  selector:
    els-pod: ui

When exposing via an AWS ELB as follows:

kubectl expose  deployment ui-deployment --type=LoadBalancer --port=80 --target-port=8080 --name=k8s-elb

I get an empty page when accessing ELB's dns name.

Furthermore, the instances behind the elb seem unhealthy:

在此处输入图片说明 Also, does the following port mapping make sense?

在此处输入图片说明

You may need some additions to your service yaml file -

  • Add loalbalancer Ip and type in Service yaml

     loadBalancerIP: <Public Ip> type: LoadBalancer 
  • ELB routing
    1. If you are hitting with HTTP or https directly with URL without specifying any port, then you need 80 and 443 both to Port on which service is running like 30001 ex - http://ip or https://ip
    2. If you want to hit open Ip say 8180, then add Rule to forward 8180 to 30001 ex - http://IP:8180/
    3. And I think you don`t need to expose deployment. Running Service yaml will work.
    4. Make sure you are providing correct ports. You may leave target port also. It will be taken same as of Port that is 8080 in your case

Refrence - https://cloud.google.com/kubernetes-engine/docs/tutorials/configuring-domain-name-static-ip

Set your service type to LoadBalancer : https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#external-load-balancer-providers

apiVersion: v1
kind: Service
metadata:
  name: ui
spec:
  type: LoadBalancer
  ports:
  - name: ui-port
    port: 8080
    targetPort: 80
  selector:
    els-pod: ui

You do not need to set a load balancer IP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM