|
1 | | -# Setup Kubernetes (K8s) Cluster on AWS |
2 | | - |
3 | | - |
4 | | -1. Create Ubuntu EC2 instance |
5 | | -1. install AWSCLI |
6 | | - ```sh |
7 | | - curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip |
8 | | - apt install unzip python |
9 | | - unzip awscli-bundle.zip |
10 | | - #sudo apt-get install unzip - if you dont have unzip in your system |
11 | | - ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws |
12 | | - ``` |
13 | | - |
14 | | -1. Install kubectl on ubuntu instance |
15 | | - ```sh |
16 | | - |
17 | | - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl |
18 | | - chmod +x ./kubectl |
19 | | - sudo mv ./kubectl /usr/local/bin/kubectl |
20 | | - ``` |
21 | | - |
22 | | -1. Install kops on ubuntu instance |
23 | | - ```sh |
24 | | - curl -LO https://github.com/kubernetes/kops/releases/download/1.15.0/kops-linux-amd64 |
25 | | - chmod +x kops-linux-amd64 |
26 | | - sudo mv kops-linux-amd64 /usr/local/bin/kops |
27 | | - kops version (it should be 1.15.0) |
28 | | - Note: use below command if you wish to use latest version. For now we could see latest version of kops. So ignore it until further update. |
29 | | - # 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 |
30 | | -
|
31 | | - ``` |
32 | | -1. Create an IAM user/role with Route53, EC2, IAM and S3 full access |
33 | | -
|
34 | | -1. Attach IAM role to ubuntu instance |
35 | | - ```sh |
36 | | - # Note: If you create IAM user with programmatic access then provide Access keys. Otherwise region information is enough |
37 | | - aws configure |
38 | | - ``` |
39 | | -
|
40 | | -1. Create a Route53 private hosted zone (you can create Public hosted zone if you have a domain) |
41 | | - ```sh |
42 | | - Routeh53 --> hosted zones --> created hosted zone |
43 | | - Domain Name: valaxy.net |
44 | | - Type: Private hosted zone for Amazon VPC. Make sure you are chosing right VPC if you have multiple |
45 | | - ``` |
46 | | -
|
47 | | -1. create an S3 bucket |
48 | | - ```sh |
49 | | - aws s3 mb s3://demo.k8s.valaxy.net |
50 | | - ``` |
51 | | -1. Expose environment variable: |
52 | | - ```sh |
53 | | - export KOPS_STATE_STORE=s3://demo.k8s.valaxy.net |
54 | | - ``` |
55 | | -
|
56 | | -1. Create sshkeys before creating cluster |
57 | | - ```sh |
58 | | - ssh-keygen |
59 | | - ``` |
60 | | -
|
61 | | -1. Create kubernetes cluster definitions on S3 bucket |
62 | | - ```sh |
63 | | - kops create cluster --cloud=aws --zones=ap-south-1b --name=demo.k8s.valaxy.net --dns-zone=valaxy.net --dns private |
64 | | - ``` |
65 | | -
|
66 | | -1. Create kubernetes cluser |
67 | | - ```sh |
68 | | - kops update cluster demo.k8s.valaxy.net --yes |
69 | | - ``` |
70 | | -1. To cahnge the kubernetes master and worker instance sizes |
71 | | - ```sh |
72 | | - kops edit ig --name=<cluster_name> nodes |
73 | | - #kops edit ig --name=demo.k8s.valaxy.net nodes |
74 | | - kops edit ig --name=<cluster_name> master-<zone_name> |
75 | | - #kops edit ig --name=demo.k8s.valaxy.net master-ap-south-1b |
76 | | - ``` |
77 | | -1. to Delete cluster (try once your lab is done) |
78 | | - ```sh |
79 | | - kops delete cluster <cluster_name> --yes |
80 | | - ``` |
81 | | -1. Validate your cluster |
82 | | - ```sh |
83 | | - kops validate cluster |
84 | | - ``` |
85 | | -
|
86 | | -1. To list nodes |
87 | | - ```sh |
88 | | - kubectl get nodes |
89 | | - ``` |
90 | | -
|
91 | | -
|
92 | | - |
93 | | -#### Deploying Nginx pods on Kubernetes |
94 | | -1. Deploying Nginx Container |
95 | | - ```sh |
96 | | - kubectl run --generator=run-pod/v1 sample-nginx --image=nginx --replicas=2 --port=80 |
97 | | - #kubectl run sample-nginx --image=nginx --replicas=2 --port=80 |
98 | | - # kubectl run simple-devops-project --image=yankils/simple-devops-image --replicas=2 --port=8080 |
99 | | - kubectl get pods |
100 | | - kubectl get deployments |
101 | | - ``` |
102 | | -
|
103 | | -1. Expose the deployment as service. This will create an ELB in front of those 2 containers and allow us to publicly access them. |
104 | | - ```sh |
105 | | - kubectl expose deployment sample-nginx --port=80 --type=LoadBalancer |
106 | | - # kubectl expose deployment simple-devops-project --port=8080 --type=LoadBalancer |
107 | | - kubectl get services -o wide |
108 | | - ``` |
| 1 | +# Setup Kubernetes (K8s) Cluster on AWS |
| 2 | + |
| 3 | + |
| 4 | +1. Create Ubuntu EC2 instance |
| 5 | +1. install AWSCLI |
| 6 | + ```sh |
| 7 | + curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip |
| 8 | + sudo apt update |
| 9 | + sudo apt install unzip python |
| 10 | + unzip awscli-bundle.zip |
| 11 | + #sudo apt-get install unzip - if you dont have unzip in your system |
| 12 | + ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws |
| 13 | + ``` |
| 14 | + |
| 15 | +1. Install kubectl on ubuntu instance |
| 16 | + ```sh |
| 17 | + curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl |
| 18 | + chmod +x ./kubectl |
| 19 | + sudo mv ./kubectl /usr/local/bin/kubectl |
| 20 | + ``` |
| 21 | + |
| 22 | +1. Install kops on ubuntu instance |
| 23 | + ```sh |
| 24 | + 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 |
| 25 | + chmod +x kops-linux-amd64 |
| 26 | + sudo mv kops-linux-amd64 /usr/local/bin/kops |
| 27 | + ``` |
| 28 | +1. Create an IAM user/role with Route53, EC2, IAM and S3 full access |
| 29 | + |
| 30 | +1. Attach IAM role to ubuntu instance |
| 31 | + ```sh |
| 32 | + # Note: If you create IAM user with programmatic access then provide Access keys. Otherwise region information is enough |
| 33 | + aws configure |
| 34 | + ``` |
| 35 | + |
| 36 | +1. Create a Route53 private hosted zone (you can create Public hosted zone if you have a domain) |
| 37 | + ```sh |
| 38 | + Routeh53 --> hosted zones --> created hosted zone |
| 39 | + Domain Name: valaxy.net |
| 40 | + Type: Private hosted zone for Amzon VPC |
| 41 | + ``` |
| 42 | + |
| 43 | +1. create an S3 bucket |
| 44 | + ```sh |
| 45 | + aws s3 mb s3://demo.k8s.valaxy.net |
| 46 | + ``` |
| 47 | +1. Expose environment variable: |
| 48 | + ```sh |
| 49 | + export KOPS_STATE_STORE=s3://demo.k8s.valaxy.net |
| 50 | + ``` |
| 51 | + |
| 52 | +1. Create sshkeys before creating cluster |
| 53 | + ```sh |
| 54 | + ssh-keygen |
| 55 | + ``` |
| 56 | + |
| 57 | +1. Create kubernetes cluster definitions on S3 bucket |
| 58 | + ```sh |
| 59 | + kops create cluster --cloud=aws --zones=ap-south-1b --name=demo.k8s.valaxy.net --dns-zone=valaxy.net --dns private |
| 60 | + ``` |
| 61 | + |
| 62 | +1. If you wish to update the cluster worker node sizes use below command |
| 63 | + ```sh |
| 64 | + kops edit ig --name=CHANGE_TO_CLUSTER_NAME nodes |
| 65 | + ``` |
| 66 | + |
| 67 | +1. Create kubernetes cluser |
| 68 | + ```sh |
| 69 | + kops update cluster demo.k8s.valaxy.net --yes |
| 70 | + ``` |
| 71 | + |
| 72 | +1. Validate your cluster |
| 73 | + ```sh |
| 74 | + kops validate cluster |
| 75 | + ``` |
| 76 | + |
| 77 | +1. To list nodes |
| 78 | + ```sh |
| 79 | + kubectl get nodes |
| 80 | + ``` |
| 81 | + |
| 82 | +1. To delete cluster |
| 83 | + ```sh |
| 84 | + kops delete cluster demo.k8s.valaxy.net --yes |
| 85 | + ``` |
| 86 | + |
| 87 | +#### Deploying Nginx pods on Kubernetes |
| 88 | +1. Deploying Nginx Container |
| 89 | + ```sh |
| 90 | + kubectl run sample-nginx --image=nginx --replicas=2 --port=80 |
| 91 | + # kubectl run simple-devops-project --image=yankils/simple-devops-image --replicas=2 --port=8080 |
| 92 | + kubectl get pods |
| 93 | + kubectl get deployments |
| 94 | + ``` |
| 95 | + |
| 96 | +1. Expose the deployment as service. This will create an ELB in front of those 2 containers and allow us to publicly access them. |
| 97 | + ```sh |
| 98 | + kubectl expose deployment sample-nginx --port=80 --type=LoadBalancer |
| 99 | + # kubectl expose deployment simple-devops-project --port=8080 --type=LoadBalancer |
| 100 | + kubectl get services -o wide |
| 101 | + ``` |
0 commit comments