Building the Kubernetes infrastructure in AWS

Amazon Web Services (AWS) is the most popular cloud service. You can launch several virtual machines on the Amazon datacenter. This section covers sign-up, setting up AWS infrastructure, and launching Kubernetes on AWS.

Getting ready

You must sign up to AWS to create an account. Access http://aws.amazon.com to put in your information and credit card number:

Getting ready

AWS registration

After registration, you may need to wait up to 24 hours in order to validate your account. After this, you will see the following page after logging on to the AWS console:

Getting ready

AWS console

How to do it…

AWS supports multiple region datacenters; you may choose the nearest and cheapest region. Inside the region, there are several Availability Zones (AZ), which are physically isolated locations that are available.

Once you choose a region, you can set up the Virtual Private Cloud (VPC) on your own network, such as 10.0.0.0/16. Inside VPC, you can also define public and private subnets that will do the following:

  • Public subnet : Allows you to assign a public IP address and access from/to public Internet via Internet Gateway
  • Private subnet : Assigns a private IP address only; can't access from public Internet, outgoing access to Internet through NAT
  • Between public subnet and private subnet are accessible

Each subnet must be located in single AZ. Therefore, it would better to create multiple public subnets and multiple private subnets in order to avoid a single point of failure (SPOF).

How to do it…

Typical VPC and subnet design

It would better to consider multiAZ for NAT; however, in this cookbook, we will skip it, as it is not necessary. For more details about the NAT gateway, please follow the link http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat-gateway.html.

Let's create this VPC on your AWS.

VPC and subnets

  1. On the AWS console, access VPC and click on Create VPC. Then, input the name tag as My Kubernetes VPC and CIDR as 10.0.0.0/16:
    VPC and subnets

    Create VPC window

    Under the VPC, subnets for both public and private on multiAZ are mentioned in the following table:

    Name Tag

    CIDR Block

    Availability Zone

    Auto-Assign Public IP

    My Kubernetes Public A

    10.0.0.0/24

    us-east-1a

    Yes

    My Kubernetes Public D

    10.0.1.0/24

    us-east-1d

    Yes

    My Kubernetes Private A

    10.0.2.0/24

    us-east-1a

    No (Default)

    My Kubernetes Private D

    10.0.3.0/24

    us-east-1d

    No (Default)

  2. Click on Subnets on the left navigation link. Then, click on the Create Subnet button. Fill out the information and choose the VPC and Availability Zone for each subnet. Repeat this four times to create four subnets:
    VPC and subnets

    Creating subnet

  3. Select the public subnet and click on the Subnet Actions button. Then, choose Modify Auto-Assign Public IP to enable public IP auto-assignment.
    VPC and subnets

    Set Auto-Assign Public IP

Internet Gateway and NAT

Each subnet should have a gateway that goes to an external network. There are two types of gateway, as follows:

  • Internet Gateway (IGW): It allows you to access from/to the Internet (bidirectional) for a server that has a public IP address
  • Network Address Translation (NAT): It allows you to access the Internet (one direction) for a server that has a private IP address

Public subnets associate with an Internet Gateway; on the other hand, private subnets can go to the Internet through NAT. Let's create IGW and NAT as follows:

Type

Associate to

Internet Gateway

VPC

NAT Gateway

Public Subnet A

Route Table

  1. After creating IGW and NAT, you need to adjust the route table to set the default gateway to IGW or NAT, as follows:

    Route Table Name

    Route Destination

    Association

    My Kubernetes Public Route

    10.0.0.0/16 local

    0.0.0.0/0 IGW

    Public Subnet A

    Public Subnet D

    My Kubernetes Private Route

    10.0.0.0/16 local

    0.0.0.0/0 NAT

    Private Subnet A

    Private Subnet D

  2. On the AWS console, click on Route Tables on the left navigation pane. Then, click on the Create Route Table button. Fill out Table Name and choose the VPN that you created. Repeat this procedure twice for a public route and private route.
  3. After creating routes, you need to add the default route as either Internet Gateway (IGW) or NAT.

    For a public route, click on the Routes tab and click on Edit. Then, add the default route as 0.0.0.0/0 and Target as the IGW ID.

    For a private route, click on the Routes tab and click on Edit. Then, add the default route as 0.0.0.0/0 and Target as the NAT Gateway ID.

    Route Table

    Set default route to NAT

  4. Finally, click on the Subnet Associations tab and then on the Edit button. Then, choose public subnets for a public route and private subnets for a private route, as follows:
    Route Table

    Associate route table to subnet

Security group

Security group is a kind of firewall to set up a rule that allows either inbound traffic or outbound traffic. For Kubernetes, there are some known traffic rules that should be set as follows:

Rule name

Inbound Protocol and port number

Source

My Kubernetes master SG

  • 8080/tcp
  • My Kubernetes node

My Kubernetes node SG

  • 30000-32767/tcp (Service)
  • 0.0.0.0/0

My etcd SG

  • 7001/tcp
  • 4001/tcp
  • 2379/tcp
  • 2380/tcp
  • My etcd SG
  • My Kubernetes master SG
  • My Kubernetes node SG

My flannel SG

  • 8285/udp
  • 8472/udp
  • My flannel SG

My ssh SG

  • 22/tcp
  • 0.0.0.0/0

On the AWS console, click on Security Groups on the left navigation pane, create five Security Groups, and add Inbound Rules, as follows:

Security group

Creating a Security Group

How it works…

Once you create your own VPC and related subnets and security groups, you can launch the EC2 instance to set up your own Kubernetes cluster. Note that the EC2 instances should be launched and associated with subnets and security groups as follows:

Instance

Subnet

Security Group

etcd

Private

  • My etcd SG
  • My ssh SG

Kubernetes node (with flannel)

Public

  • My flannel SG
  • My Kubernetes node SG
  • My ssh SG

Kubernetes master (with flannel)

Private

  • My flannel SG
  • My Kubernetes master SG
  • My ssh SG
How it works…

Minimal configuration of the Kubernetes cluster in the AWS VPC

See also

In this recipe, you learned how to register Amazon Web Services and how to create your own infrastructure. AWS provides a huge number of services; however, it has a lot of documentation and related webinars online. It is recommended that you read and watch to understand the best practices to use the AWS infrastructure. Following is a list of good resources:

Furthermore, look at the following recipes:

  • The Building datastore and Creating an overlay network recipes in Chapter 1, Building Your Own Kubernetes
  • Managing applications using AWS OpsWorks
  • Auto-deploying Kubernetes through Chef recipes
  • Using AWS CloudFormation for fast provisioning
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset