|
| 1 | +<<kops |
| 2 | +Landmark Technologies |
| 3 | +Tel: +1 437 215 2483 |
| 4 | +mylandmarktech@gailcom |
| 5 | +www.mylandmarktech.com |
| 6 | +kops |
| 7 | +Setup Kubernetes (K8s) Cluster on AWS Using KOPS |
| 8 | + |
| 9 | +#!/bin/bash |
| 10 | +#1) Create Ubuntu EC2 instance |
| 11 | + |
| 12 | +#2) install AWSCLI |
| 13 | + |
| 14 | + sudo apt update -y |
| 15 | + sudo apt install unzip wget -y |
| 16 | + sudo curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip |
| 17 | + sudo apt install unzip python -y |
| 18 | + sudo unzip awscli-bundle.zip |
| 19 | + sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws |
| 20 | + |
| 21 | + |
| 22 | +#3) Install kops on ubuntu instance: |
| 23 | + |
| 24 | + #Install wget if not installed |
| 25 | + sudo apt install wget -y |
| 26 | + sudo wget https://github.com/kubernetes/kops/releases/download/v1.16.1/kops-linux-amd64 |
| 27 | + sudo chmod +x kops-linux-amd64 |
| 28 | + sudo mv kops-linux-amd64 /usr/local/bin/kops |
| 29 | + |
| 30 | +#4) Install kubectl |
| 31 | + |
| 32 | + 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 |
| 33 | + sudo chmod +x ./kubectl |
| 34 | + sudo mv ./kubectl /usr/local/bin/kubectl |
| 35 | + aws s3 mb s3://nubonglegah.k8.local |
| 36 | + aws s3 ls |
| 37 | + |
| 38 | +5) Create an IAM role from Consloe or CLI with below Policies. |
| 39 | + |
| 40 | + AmazonEC2FullAccess |
| 41 | + AmazonS3FullAccess |
| 42 | + IAMFullAccess |
| 43 | + AmazonVPCFullAccess |
| 44 | + |
| 45 | + |
| 46 | +Then Attach IAM role to ubuntu server from Console Select KOPS Server --> Actions --> Instance Settings --> Attach/Replace IAM Role --> Select the role which |
| 47 | +You Created. --> Save. |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +6) create an S3 bucket Execute below commond in KOPS Server use unique bucket name if you get bucket name exists error. |
| 52 | + |
| 53 | + aws s3 mb s3://nubonglegah.k8.local |
| 54 | + aws s3 ls |
| 55 | + |
| 56 | + ex: |
| 57 | + # S3 bucket name should be unique across AWS |
| 58 | + aws s3 mb s3://simonlegah.k8s.local s3://nubong.k8s.local |
| 59 | + |
| 60 | + Expose environment variable: |
| 61 | + |
| 62 | + # Add env variables in bashrc |
| 63 | + vi .bashrc |
| 64 | + |
| 65 | + # Give Unique Name And S3 Bucket which you created. |
| 66 | + export NAME=s3://legah2045.k8.local |
| 67 | + export KOPS_STATE_STORE=s3://legah2045.k8.local |
| 68 | + |
| 69 | + source .bashrc |
| 70 | + |
| 71 | +7) Create sshkeys before creating cluster |
| 72 | + |
| 73 | + ssh-keygen |
| 74 | + |
| 75 | + |
| 76 | +8)Create kubernetes cluster definitions on S3 bucket |
| 77 | + |
| 78 | + kops create cluster --zones us-east-2c --networking weave --master-size t2.medium --master-count 1 --node-size t2.large --node-count=2 ${NAME} |
| 79 | + |
| 80 | + kops create cluster --zones us-east-1e,zones us-east-2c --networking weave --master-size t2.medium --master-count 2 --node-size t2.micro --node-count=2 ${NAME} |
| 81 | + |
| 82 | + kops create secret --name ${NAME} sshpublickey admin -i ~/.ssh/id_rsa.pub |
| 83 | + |
| 84 | +9) Create kubernetes cluser |
| 85 | + |
| 86 | + kops update cluster ${NAME} --yes |
| 87 | + |
| 88 | +10) Validate your cluster(KOPS will take some time to create cluster ,Execute below commond after 3 or 4 mins) |
| 89 | + |
| 90 | + kops validate cluster |
| 91 | + |
| 92 | +11) To list nodes |
| 93 | + |
| 94 | + kubectl get nodes |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +To Delete Cluster |
| 99 | + |
| 100 | + kops delete cluster --name=${NAME} --state=${KOPS_STATE_STORE} --yes |
| 101 | + |
| 102 | +==================================================================================================== |
| 103 | + |
| 104 | + |
| 105 | +IF you wan to SSH to Kubernates Master or Nodes Created by KOPS. You can SSH From KOPS_Server |
| 106 | + |
| 107 | +ssh admin@<IPOrDNS> |
| 108 | +it above command is not working |
| 109 | +then execute |
| 110 | +ssh -i ~/.ssh/id_rsa admin@<IPOrDNS> |
| 111 | + |
0 commit comments