Skip to content

benadaba/k8s-kops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

kops-kubernetes-cluster-configuration

DataPandas, - DataPandas

Setting up Kubernetes (K8s) Cluster on AWS Using KOPS

1.kops is a software use to create production ready k8s cluster in a cloud provider like AWS.

  1. kOPS SUPPORTS MULTIPLE CLOUD PROVIDERS

  2. Kops compete with managed kubernestes services like EKS, AKS and GKE

  3. Kops is cheaper than the others.

  4. Kops create production ready K8S.

  5. KOPS create resources like: LoadBalancers, ASG, Launch Configuration, woker node Master node (CONTROL PLANE.

  6. KOPS is IaaC

#!/bin/bash

1) Create Ubuntu EC2 instance in AWS

2) create kops user

 sudo adduser kops
 sudo echo "kops  ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/kops
 sudo su - kops

or 3a) install AWSCLI using the script below

sudo apt update -y
sudo apt install unzip wget -y
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

3b) install AWSCLI using the apt package manager

sudo apt install awscli -y 

or 3c) install AWSCLI using the script below

sudo apt update -y
sudo apt install unzip wget -y
sudo curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip
sudo apt install unzip python -y
# or sudo apt install unzip python3 -y
sudo unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

4) Install kops software on an ubuntu instance by running the commands below:

  sudo apt install wget -y
  #sudo wget https://github.com/kubernetes/kops/releases/download/v1.22.0/kops-linux-amd64
      sudo wget https://github.com/kubernetes/kops/releases/download/v1.30.0/kops-linux-amd64
  sudo chmod +x kops-linux-amd64
  sudo mv kops-linux-amd64 /usr/local/bin/kops

OR

sudo curl -Lo kops 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
sudo chmod +x ./kops
sudo mv ./kops /usr/local/bin/

5) Install kubectl kubernetes client if it is not already installed

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

6) Create an IAM role from AWS Console or CLI with the below Policies.

AmazonEC2FullAccess 
AmazonS3FullAccess
IAMFullAccess 
AmazonVPCFullAccess

Then Attach IAM role to ubuntu server from Console Select KOPS Server --> Actions --> Instance Settings --> Attach/Replace IAM Role --> Select the role which You Created. --> Save.

7) create an S3 bucket. this bucket will act as a key-value store

Execute the commands below in your KOPS control Server. use unique s3 bucket name. If you get bucket name exists error.

aws s3 mb s3://datapandaskops
aws s3 ls # to verify

7b) create an S3 bucket

Expose environment variable:
# Add env variables in bashrc

   vi .bashrc
# Give Unique Name And S3 Bucket which you created.
export NAME=datapandas.k8s.local
export KOPS_STATE_STORE=s3://datapandaskops

  source .bashrc  

8) Create sshkeys before creating cluster

    #ssh-keygen
    ssh-keygen -t rsa -b 4096

9) Create kubernetes cluster definitions on S3 bucket

#kops create cluster --zones eu-west-2a --networking weave --master-size t2.medium --master-count 1 --node-size t2.medium --node-count=2 ${NAME}
kops create cluster --zones eu-west-2a  --control-plane-size t2.medium --control-plane-count 1 --node-size t2.medium --node-count=2 ${NAME}
# copy the sshkey into your cluster to be able to access your kubernetes node from the kops server
kops create secret --name ${NAME} sshpublickey admin -i ~/.ssh/id_rsa.pub

10) Initialise your kops kubernetes cluser by running the command below

kops update cluster ${NAME} --yes

10a - Export the kubeconfig file to manage your kubernetes cluster from a remote server. For this demo, Our remote server shall be our kops server

 kops export kubecfg $NAME --admin

10b) Validate your cluster(KOPS will take some time to create cluster ,Execute below commond after 3 or 4 mins)

kops validate cluster

   Suggestions:
  • validate cluster: kops validate cluster --wait 10m
  • list nodes: kubectl get nodes --show-labels
  • ssh to the master: ssh -i ~/.ssh/id_rsa ubuntu@
  • the ubuntu user is specific to Ubuntu. If not using Ubuntu please use the appropriate user based on your OS.
  • read about installing addons at: https://kops.sigs.k8s.io/operations/addons.

11a) To list nodes and pod to ensure that you can make calls to the kubernetes apiSAerver and run workloads

  kubectl get nodes 

11b) Alternative you can ssh into your kubernetes master server using the command below and manage your cluster from the master

ssh ubuntu@<ip-Address-of-master-node>
ssh  ubuntu@18.222.139.125
ssh  ubuntu@172.20.58.124

11b. Alternative, Enable PasswordAuthentication in the master server and assign passwd

sudo sed -i "/^[^#]*PasswordAuthentication[[:space:]]no/c\PasswordAuthentication yes" /etc/ssh/sshd_config
sudo service sshd restart
sudo passwd ubuntu

11c) To list nodes

  kubectl get nodes 

12) To Delete Cluster

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

====================================================================================================

13 # IF you want to SSH to Kubernetes Master or Nodes Created by KOPS. You can SSH From KOPS_Server

sh -i ~/.ssh/id_rsa ubuntu@ipAddress ssh -i ~/.ssh/id_rsa ubuntu@3.90.203.23

``

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published