Skip to content

sunnygodiwal1991/kubernetes

Repository files navigation

Kubernetes on AWS using Kops

1. Launch Linux EC2 instance in AWS

2. Create IAM role for EC2 with admin access.

Attach Iam role to EC2 instance

3. Install Kops on EC2

curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
chmod +x kops-linux-amd64
sudo mv kops-linux-amd64 /usr/local/bin/kops

4. Install kubelet

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.12.0/bin/linux/amd64/kubectl chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl

Create S3 bucket in AWS

S3 bucket is used by kubernetes to persist cluster state

$bucket_name=sample-kops-state-store
$aws s3 mb s3://${bucket_name} --region us-west-2

Create domain from free websites dot.tk

  Create Hosted Zone under AWS Route 53, Hosted Zone name must match with domain you created in previous step
  Takse DNS servers and update them in dot.tk under your domain name servers

Provide a name for the Kubernetes cluster and set the S3 bucket URL in the following environment variables.

export KOPS_CLUSTER_NAME=sample.com
export KOPS_STATE_STORE=s3://${bucket_name}

Create a ssh key pair before run the create cluster command this is used in

$ssh-keygen

kops create cluster help command to find additional parameters.

$kops create cluster --help

Create a Kubernetes cluster definition using kops by providing the required fields.

$kops create cluster \
--state=${KOPS_STATE_STORE} \
--node-count=2 \
--master-size=t2.micro \
--node-size=t2.micro \
--zones=us-west-1a \
--name=${KOPS_CLUSTER_NAME}

If it show any ssh required after running above command

$kops create secret sshpublickey admin -i ~/.ssh/id_rsa.pub --name=${KOPS_CLUSTER_NAME} --state=${KOPS_STATE_STORE}

Review the Kubernetes cluster definition by executing the below command

$kops edit cluster --name=${KOPS_CLUSTER_NAME} --state=${KOPS_STATE_STORE}

Now create the Kubernetes cluster on AWS by executing kops update command

$kops update cluster --name=${KOPS_CLUSTER_NAME} --state=${KOPS_STATE_STORE} --yes

Above command may take some time to create the required infrastructure resources on AWS. Execute the validate command to check its status and wait until the cluster becomes ready

$kops validate cluster --state=${KOPS_STATE_STORE} --name=${KOPS_CLUSTER_NAME}

Execute the below command to find the Kubernetes master hostname using kubectl

$kubectl cluster-info

To connect to the master and check the connection

$ssh -i ~/.ssh/id_rsa admin@api.sample.com

Destroy the kubernetes cluster using below command

$kops delete cluster --state=${KOPS_STATE_STORE} --name=${KOPS_CLUSTER_NAME} --yes

This site was built using GitHub Pages.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published