In Kubernetes, there is a concept of cloud providers, which is a module which provides an interface for managing load balancers, nodes (i.e. hosts) and networking routes.
Currently, Rancher supports two cloud providers when installing Kubernetes.
rancher/lb-service-haproxy
image, as a Load Balancer service. By default, the load balancer will round robin traffic to the pods.By default, the orchestration for Kubernetes is set to rancher
.
Before creating a Kubernetes environment, the Kubernetes infrastructure stack will need to be configured and the configuration option for the Cloud Provider will need to be set as aws
.
When creating new environments, you will need to select an environment template that is already configured correctly. When adding or editing an environment template, the orchestration will need to have Kubernetes selected. Click on Edit Config. Pick aws
in the Configuration Options -> Cloud Provider and click Configure.
For existing Kubernetes environment templates, you can edit the environment template under the Manage Environments link from the drop down of environments. Click on the Edit icon next to the environment template running Kubernetes.
If you have an existing Cattle environment, the environment can be converted to a Kubernetes orchestration by going to Catalog -> library and selecting Kubernetes. Click on View Details and switch to aws
for the Cloud Provider. Click on Launch
After Kubernetes has been configured to run with an aws
cloud provider, any hosts added into the environment will need to be an AWS EC2 instance and have at least the following IAM policy:
{
"Effect": "Allow",
"Action": "ec2:Describe*",
"Resource": "*"
}
In order to use Elastic Load Balancers (ELB) and EBS with Kubernetes, the host will need to have the an IAM role with appropriate access.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:Describe*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "ec2:AttachVolume",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "ec2:DetachVolume",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": ["ec2:*"],
"Resource": ["*"]
},
{
"Effect": "Allow",
"Action": ["elasticloadbalancing:*"],
"Resource": ["*"]
}
]
}
After configuring Kubernetes to use aws
as a cloud provider and ensuring the host has the appropriate IAM policy for ELB, you can start creating load balancers.
lb.yml
apiVersion: v1
kind: Service
metadata:
name: nginx-lb
labels:
app: nginx
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- name: http
port: 80
protocol: TCP
Using kubectl
, let’s launch our load balancer service into Kubernetes. Remember, you can either configure kubectl
for your local machine or you can use the shell in the UI under Kubernetes -> kubectl.
$ kubectl create -f lb.yml
service "nginx-lb" created
$ kubectl describe services nginx-lb
Name: nginx-lb
Namespace: default
Labels: app=nginx
Selector: name=nginx
Type: LoadBalancer
IP: 10.43.137.5
LoadBalancer Ingress: a4c7d4290f48011e690470275ac52fef-1158549671.us-west-2.elb.amazonaws.com
Port: http 80/TCP
NodePort: http 32166/TCP
Endpoints: <none>
Session Affinity: None
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
17s 17s 1 {service-controller } Normal CreatingLoadBalancer Creating load balancer
14s 14s 1 {service-controller } Normal CreatedLoadBalancer Created load balancer
After configuring Kubernetes to use aws
as a cloud provider and ensuring the host has the appropriate IAM policy for EBS, you can start using EBS volumes.