Scroll Top

Installing Kubernetes cluster on AWS using KOPS

Kubernetes cluster on AWS

This blog will show you how to install a Kubernetes cluster on AWS using KOPS.

Requirements

You must have kubectl , kops and aws-cli installed on your system. For AWS operations, we will be using AWS CLI for our usage but same can be done using AWS GUI.

You should have an IAM user created and configured with aws-cli.

Installation

Create a route53 domain for your Kubernetes cluster:

[bash]

MacBook-Pro$ aws route53 create-hosted-zone –name dev.coderise.io –caller-reference 1
Output:
{
“Location”: “https://route53.amazonaws.com/2013-04-01/hostedzone/Z2832T6XCLVV1U2”,
“HostedZone”: {
“Id”: “/hostedzone/Z2832T6GELVVU2”,
“Name”: “dev.coderise.io.”,
“CallerReference”: “1”,
“Config”: {
“PrivateZone”: false
},
“ResourceRecordSetCount”: 2
},
“ChangeInfo”: {
“Id”: “/change/C3LK4K8RRWE9VQ”,
“Status”: “PENDING”,
“SubmittedAt”: “2018-04-07T19:27:53.964Z”
},
“DelegationSet”: {
“NameServers”: [
“ns-1168.awsdns-05.org”,
“ns-917.awsdns-12.com”,
“ns-1173.awsdns-04.co.uk”,
“ns-913.awsdns-56.net”
]
}
}

[/bash]

Create a new NS record for ‘dev’ in the parent domain ‘coderise.io’ so that the records in the domain will resolve.

Double-check your cluster route 53 entry got created correctly:

[bash]
MacBook-Pro$ dig NS dev.coderise.io

; <<>> DiG 9.9.7-P3 <<>> NS dev.coderise.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18782
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;dev.coderise.io. IN NS

;; ANSWER SECTION:
dev.coderise.io. 172800 IN NS ns-1068.awsdns-05.org.
dev.coderise.io. 172800 IN NS ns-1573.awsdns-04.co.uk.
dev.coderise.io. 172800 IN NS ns-963.awsdns-56.net.
dev.coderise.io. 172800 IN NS ns-97.awsdns-12.com.

;; Query time: 10 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Sat Apr 07 16:12:07 EDT 2018
;; MSG SIZE rcvd: 172
[/bash]

Create an S3 bucket to store Kubernetes clusters state:

[bash]
MacBook-Pro$ aws s3 mb s3://clusters.dev.coderise.io
make_bucket: clusters.dev.coderise.io
[bash]

Export KOPS_STATE_STORE to use S3 bucket:

You can put the export command in your bash_profile or similar.
[bash]
MacBook-Pro:$ export KOPS_STATE_STORE=s3://clusters.dev.coderise.io
[/bash]

Export Kubernetes cluster configuration:

[bash]

MacBook-Pro$ kops create cluster –zones=us-east-1c useast1.dev.coderise.io
Output:
I0407 16:13:36.276014 43671 create_cluster.go:439] Inferred –cloud=aws from zone “us-east-1c”
I0407 16:13:36.276232 43671 create_cluster.go:971] Using SSH public key: /Users/coderiseio/.ssh/id_rsa.pub
I0407 16:13:36.523103 43671 subnets.go:184] Assigned CIDR 172.20.32.0/19 to subnet us-east-1c
Previewing changes that will be made:

Cluster configuration has been created.

Suggestions:
* list clusters with: kops get cluster
* edit this cluster with: kops edit cluster useast1.dev.coderise.io
* edit your node instance group: kops edit ig –name=useast1.dev.coderise.io nodes
* edit your master instance group: kops edit ig –name=useast1.dev.coderise.io master-us-east-1c

Finally configure your cluster with: kops update cluster useast1.dev.coderise.io –yes

[/bash]

Create Kubernetes cluster on AWS:

[bash]

MacBook-Pro$ kops update cluster useast1.dev.coderise.io –yes
I0407 16:21:17.206920 43735 executor.go:91] Tasks: 0 done / 73 total; 31 can run
I0407 16:21:17.708441 43735 vfs_castore.go:435] Issuing new certificate: “ca”
I0407 16:21:17.814842 43735 vfs_castore.go:435] Issuing new certificate: “apiserver-aggregator-ca”
I0407 16:21:18.829155 43735 executor.go:91] Tasks: 31 done / 73 total; 24 can run
I0407 16:21:19.216742 43735 vfs_castore.go:435] Issuing new certificate: “kubelet-api”
I0407 16:21:19.230615 43735 vfs_castore.go:435] Issuing new certificate: “kubecfg”
I0407 16:21:19.395379 43735 vfs_castore.go:435] Issuing new certificate: “apiserver-aggregator”
I0407 16:21:19.722587 43735 vfs_castore.go:435] Issuing new certificate: “kube-proxy”
I0407 16:21:19.812891 43735 vfs_castore.go:435] Issuing new certificate: “kube-controller-manager”
I0407 16:21:19.834717 43735 vfs_castore.go:435] Issuing new certificate: “master”
I0407 16:21:19.846264 43735 vfs_castore.go:435] Issuing new certificate: “kube-scheduler”
I0407 16:21:19.927029 43735 vfs_castore.go:435] Issuing new certificate: “kops”
I0407 16:21:19.991106 43735 vfs_castore.go:435] Issuing new certificate: “kubelet”
I0407 16:21:20.049809 43735 vfs_castore.go:435] Issuing new certificate: “apiserver-proxy-client”
I0407 16:21:20.165704 43735 executor.go:91] Tasks: 55 done / 73 total; 16 can run
I0407 16:21:20.759989 43735 launchconfiguration.go:333] waiting for IAM instance profile “masters.useast1.dev.coderise.io” to be ready
I0407 16:21:20.790445 43735 launchconfiguration.go:333] waiting for IAM instance profile “nodes.useast1.dev.coderise.io” to be ready
I0407 16:21:31.325210 43735 executor.go:91] Tasks: 71 done / 73 total; 2 can run
I0407 16:21:32.131191 43735 executor.go:91] Tasks: 73 done / 73 total; 0 can run
I0407 16:21:32.131263 43735 dns.go:153] Pre-creating DNS records
I0407 16:21:33.228075 43735 update_cluster.go:248] Exporting kubecfg for cluster
kops has set your kubectl context to useast1.dev.coderise.io

Cluster is starting. It should be ready in a few minutes.

Suggestions:
* validate cluster: kops validate cluster
* list nodes: kubectl get nodes –show-labels
* ssh to the master: ssh -i ~/.ssh/id_rsa [email protected]

[/bash]

You can run the following command to view pods –

[bash]

MacBook-Pro$ kubectl get pods –all-namespaces

NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system dns-controller-74747d4d68-qzgpq 1/1 Running 0 2h
kube-system etcd-server-events-ip-172-20-51-254.ec2.internal 1/1 Running 0 2h
kube-system etcd-server-ip-172-20-51-254.ec2.internal 1/1 Running 0 2h
kube-system kube-apiserver-ip-172-20-51-254.ec2.internal 1/1 Running 0 2h
kube-system kube-controller-manager-ip-172-20-51-254.ec2.internal 1/1 Running 0 2h
kube-system kube-dns-7f56f9f8c7-764kj 3/3 Running 0 2h
kube-system kube-dns-7f56f9f8c7-8bq2b 3/3 Running 0 2h
kube-system kube-dns-autoscaler-f4c47db64-tzsg2 1/1 Running 0 2h
kube-system kube-proxy-ip-172-20-51-254.ec2.internal 1/1 Running 0 2h
kube-system kube-proxy-ip-172-20-52-39.ec2.internal 1/1 Running 0 2h
kube-system kube-proxy-ip-172-20-62-62.ec2.internal 1/1 Running 0 2h
kube-system kube-scheduler-ip-172-20-51-254.ec2.internal 1/1 Running 0 2h

[/bash]

Deploying a sample Nginx app:

[bash]
MacBook-Pro$ kubectl run app-nginx –image=nginx –port=80
deployment “app-nginx” created

MacBook-Pro$ kubectl get pods -n default
NAME READY STATUS RESTARTS AGE
app-nginx-79f68db4bf-v6vzq 1/1 Running 0 3m
[/bash]

Your Kubernetes cluster on AWS is all setup and ready to use, enjoy!

Next steps

Once you have your Kubernetes cluster on AWS all setup and ready, you can check out our modern CI CD kubernetes deployment pipeline blog and start deploying applications in your cluster.

References

https://kubernetes.io/docs/getting-started-guides/kops/

Related Posts

Leave a comment