Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Kubernetes load balancer on aws

Kubernetes create a load balancer, for each service; automatically in GCE. How can I manage something similar on AWS?

Kubernetes service basically use the kubeproxy to handle the internal traffic. But that kubeproxy ip its do not have access to the external network.

There its a way to accomplish this?

like image 858
bitgandtter Avatar asked Jul 24 '15 13:07

bitgandtter


People also ask

Is there a load balancer in Kubernetes?

The Kubernetes load balancer sends connections to the first server in the pool until it is at capacity, and then sends new connections to the next available server. This algorithm is ideal where virtual machines incur a cost, such as in hosted environments.

Does EKS use load balancer?

When you create a Kubernetes ingress , an AWS Application Load Balancer (ALB) is provisioned that load balances application traffic.


2 Answers

In your service definition, set its type field to LoadBalancer, and kubernetes will automatically create an AWS Elastic Load Balancer for you if you're running on AWS. This feature should work on GCE/GKE, AWS, and OpenStack.

For an example, check out the guestbook-go example.

like image 79
Alex Robinson Avatar answered Oct 02 '22 04:10

Alex Robinson


Minimal example:

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  type: LoadBalancer
  selector:
    app: MyApp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9376

The relevant docs:

  • Create an External Load Balancer
  • Type LoadBalancer

As of writing the best way to learn about all the service.beta.kubernetes.io annotations is to read the source code:

  • cloudprovider/providers/aws/aws.go

For the controller to be able to manage the ELB it will need permissions set in the master instances IAM Role, e.g.:

...
{
  "Action": "elasticloadbalancing:*",
  "Resource": "*",
  "Effect": "Allow"
},
{
  "Action": [
    "ecr:GetAuthorizationToken",
    "ecr:BatchCheckLayerAvailability",
    "ecr:GetDownloadUrlForLayer",
    "ecr:GetRepositoryPolicy",
    "ecr:DescribeRepositories",
    "ecr:ListImages",
    "ecr:BatchGetImage"
  ],
  "Resource": "*",
  "Effect": "Allow"
},
...

The cloud provider should be set with --cloud-provider=aws on kube-apiserver.

like image 44
Paweł Prażak Avatar answered Oct 02 '22 06:10

Paweł Prażak