Provisioning a Kubernetes cluster on Amazon EC2

This recipe will take you through how to get a fully functional Kubernetes cluster with fully customizable master and worker nodes that you can use for the recipes in the following chapters or in production.

Let's perform the following steps:

  1. Create a domain for your cluster.
It is a cloud management best practice to have subdomains and to divide your clusters with logical and valid DNS names for kops to successfully discovery them.

As an example, I will use the k8s.containerized.me subdomain as our hosted zone. Also, if your domain is registered with a registrar other than Amazon Route 53, you must update the name servers with your registrar and add Route 53 NS records for the hosted zone to your registrar's DNS records: 

$ aws route53 create-hosted-zone --name k8s.containerized.me 
--caller-reference k8s-devops-cookbook
--hosted-zone-config Comment="Hosted Zone for my K8s Cluster"
  1. Create an S3 bucket to store the Kubernetes configuration and the state of the cluster. In our example, we will use s3.k8s.containerized.me as our bucket name:
$ aws s3api create-bucket --bucket s3.k8s.containerized.me 
--region us-east-1
  1. Confirm your S3 bucket by listing the available bucket:
$ aws s3 ls
2019-07-21 22:02:58 s3.k8s.containerized.me
  1. Enable bucket versioning:
$ aws s3api put-bucket-versioning --bucket s3.k8s.containerized.me 
--versioning-configuration Status=Enabled
  1. Set environmental parameters for kops so that you can use the locations by default:
$ export KOPS_CLUSTER_NAME=useast1.k8s.containerized.me
$ export KOPS_STATE_STORE=s3://s3.k8s.containerized.me
  1. Create an SSH key if you haven't done so already:
$ ssh-keygen -t rsa
  1. Create the cluster configuration with the list of zones where you want your master nodes to run:
$ kops create cluster --node-count=6 --node-size=t3.large 
--zones=us-east-1a,us-east-1b,us-east-1c
--master-size=t3.large
--master-zones=us-east-1a,us-east-1b,us-east-1c
  1. Create the cluster:
$ kops update cluster --name ${KOPS_CLUSTER_NAME} --yes
  1. Wait a couple of minutes for the nodes to launch and validate:
$ kops validate cluster
  1. Now, you can use kubectl to manage your cluster:
$ kubectl cluster-info

By default, kops creates and exports the Kubernetes configuration under ~/.kube/config. Therefore, no additional steps are required to connect your clusters using kubectl.

..................Content has been hidden....................

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