Skip to content

Commit aa2ff42

Browse files
unknownunknown
authored andcommitted
added Kuberenetes setup procedure
1 parent 05222af commit aa2ff42

File tree

3 files changed

+289
-108
lines changed

3 files changed

+289
-108
lines changed
Lines changed: 101 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,101 @@
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+
```
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Kubernetes Cluster installation using kubeadm
2+
Follow this documentation to set up a Kubernetes cluster on __CentOS__ 7 machines.
3+
4+
This documentation guides you in setting up a cluster with one master node and two worker nodes.
5+
6+
## Prerequisites:
7+
1. System Requirements
8+
>Master: t2.medium (2 CPUs and 2GB Memory)
9+
>Worker Nodes: t2.micro
10+
11+
1. Open Below ports in the Security Group.
12+
#### Master node:
13+
`6443
14+
32750
15+
10250
16+
4443
17+
443
18+
8080 `
19+
20+
##### On Master node and Worker node:
21+
`179`
22+
23+
### `On Master and Worker:`
24+
1. Perform all the commands as root user unless otherwise specified
25+
26+
Install, Enable and start docker service.
27+
Use the Docker repository to install docker.
28+
> If you use docker from CentOS OS repository, the docker version might be old to work with Kubernetes v1.13.0 and above
29+
30+
```sh
31+
yum install -y -q yum-utils device-mapper-persistent-data lvm2 > /dev/null 2>&1
32+
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo > /dev/null 2>&1
33+
yum install -y -q docker-ce >/dev/null 2>&1
34+
```
35+
1. Start Docker services
36+
```sh
37+
systemctl enable docker
38+
systemctl start docker
39+
```
40+
1. Disable SELinux
41+
```sh
42+
setenforce 0
43+
sed -i --follow-symlinks 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
44+
```
45+
1. Disable Firewall
46+
```sh
47+
systemctl disable firewalld
48+
systemctl stop firewalld
49+
```
50+
1. Disable swap
51+
```sh
52+
sed -i '/swap/d' /etc/fstab
53+
swapoff -a
54+
```
55+
1. Update sysctl settings for Kubernetes networking
56+
```sh
57+
cat >> /etc/sysctl.d/kubernetes.conf <<EOF
58+
net.bridge.bridge-nf-call-ip6tables = 1
59+
net.bridge.bridge-nf-call-iptables = 1
60+
EOF
61+
sysctl --system
62+
```
63+
## Kubernetes Setup
64+
1. Add yum repository for kubernetes packages
65+
```sh
66+
cat >>/etc/yum.repos.d/kubernetes.repo<<EOF
67+
[kubernetes]
68+
name=Kubernetes
69+
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
70+
enabled=1
71+
gpgcheck=1
72+
repo_gpgcheck=1
73+
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
74+
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
75+
EOF
76+
```
77+
1. Install Kubernetes
78+
```sh
79+
yum install -y kubeadm-1.15.6-0.x86_64 kubelet-1.15.6-0.x86_64 kubectl-1.15.6-0.x86_64
80+
```
81+
1. Enable and Start kubelet service
82+
```sh
83+
systemctl enable kubelet
84+
systemctl start kubelet
85+
```
86+
## `On Master Node:`
87+
1. Initialize Kubernetes Cluster
88+
```sh
89+
kubeadm init --apiserver-advertise-address=<MasterServerIP> --pod-network-cidr=192.168.0.0/16
90+
```
91+
1. Create a user for kubernetes administration and copy kube config file.
92+
``To be able to use kubectl command to connect and interact with the cluster, the user needs kube config file.``
93+
In this case, we are creating a user called `kubeadmin`
94+
```sh
95+
useradd kubeadmin
96+
mkdir /home/kubeadmin/.kube
97+
cp /etc/kubernetes/admin.conf /home/kubeadmin/.kube/config
98+
chown -R kubeadmin:kubeadmin /home/kubeadmin/.kube
99+
```
100+
1. Deploy Calico network as a __kubeadmin__ user.
101+
> This should be executed as a user (heare as a __kubeadmin__ )
102+
103+
```sh
104+
sudo su - kubeadmin
105+
kubectl create -f https://docs.projectcalico.org/v3.9/manifests/calico.yaml
106+
```
107+
108+
1. Cluster join command
109+
```sh
110+
kubeadm token create --print-join-command
111+
```
112+
## `On Worker Node:`
113+
1. Add worker nodes to cluster
114+
> Use the output from __kubeadm token create__ command in previous step from the master server and run here.
115+
116+
1. Verifying the cluster
117+
To Get Nodes status
118+
```sh
119+
kubectl get nodes
120+
```
121+
To Get component status
122+
```sh
123+
kubectl get cs
124+
```
125+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Setup Kubernetes on Amazon EKS
2+
3+
You can follow same procedure in the official AWS document [Getting started with Amazon EKS – eksctl](https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html)
4+
5+
#### Pre-requisites:
6+
- an EC2 Instance
7+
8+
#### AWS EKS Setup
9+
1. Setup kubectl
10+
a. Download kubectl version 1.20
11+
b. Grant execution permissions to kubectl executable
12+
c. Move kubectl onto /usr/local/bin
13+
d. Test that your kubectl installation was successful
14+
```sh
15+
chmod +x ./kubectl
16+
curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl
17+
mv ./kubectl /usr/local/bin
18+
kubectl version --short --client
19+
```
20+
2. Setup eksctl
21+
a. Download and extract the latest release
22+
b. Move the extracted binary to /usr/local/bin
23+
c. Test that your eksclt installation was successful
24+
```sh
25+
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
26+
sudo mv /tmp/eksctl /usr/local/bin
27+
eksctl version
28+
```
29+
30+
3. Create an IAM Role and attache it to EC2 instance
31+
`Note: create IAM user with programmatic access if your bootstrap system is outside of AWS`
32+
IAM user should have access to
33+
IAM
34+
EC2
35+
VPC
36+
CloudFormation
37+
38+
4. Create your cluster and nodes
39+
```sh
40+
eksctl create cluster --name cluster-name \
41+
--region region-name \
42+
--node-type instance-type \
43+
--nodes-min 2 \
44+
--nodes-max 2 \
45+
--zones <AZ-1>,<AZ-2>
46+
47+
example:
48+
eksctl create cluster --name valaxy-cluster \
49+
--region ap-south-1 \
50+
--node-type t2.small \
51+
```
52+
53+
5. To delete the EKS clsuter
54+
```sh
55+
eksctl delete cluster valaxy --region ap-south-1
56+
```
57+
58+
6. Validate your cluster using by creating by checking nodes and by creating a pod
59+
```sh
60+
kubectl get nodes
61+
kubectl run pod tomcat --image=tomcat
62+
```
63+

0 commit comments

Comments
 (0)