How to create Kubernetes load balancer on aws

一个人想着一个人 提交于 2019-11-30 23:15:04

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/31611503/how-to-create-kubernetes-load-balancer-on-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!