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