Standing up a kubernetes cluster on AWS using kops and Travis-CI as CI/CD Pipeline
You can find the source code and the different Dockerfile in the directory udagram-prject
that is how the cluster will look like
Update and load the required environment variables:
The domain name that is hosted in AWS Route 53
export DOMAIN_NAME="kops.ucci.uk"Friendly name to use as an alias for our cluster
export CLUSTER_ALIAS="udagramk8s"Full DNS name of our cluster
export CLUSTER_FULL_NAME="${CLUSTER_ALIAS}.${DOMAIN_NAME}"AWS availability zone where the cluster will be created
export CLUSTER_AWS_AZ="us-east-1a"AWS Route 53 hosted zone ID for your domain
export DOMAIN_NAME_ZONE_ID=$(aws route53 list-hosted-zones \
| jq -r '.HostedZones[] | select(.Name=="'${DOMAIN_NAME}'.") | .Id' \
| sed 's/\/hostedzone\///') Note : you have to configure the aws profile first aws configure, the IAM must the following policies attached to it
AmazonEC2FullAccess
AmazonRoute53FullAccess
AmazonS3FullAccess
IAMFullAccess
AmazonVPCFullAccess
We use Kops to stand up the cluster
Create the S3 bucket in AWS, which will be used by Kops for cluster configuration storage:
aws s3api create-bucket --bucket ${CLUSTER_FULL_NAME}-state --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2Set the KOPS_STATE_STORE variable to the URL of the S3 bucket that was just created:
export KOPS_STATE_STORE="s3://${CLUSTER_FULL_NAME}-state"Create the cluster with Kops:
kops create cluster \
--name=${CLUSTER_FULL_NAME} \
--zones=${CLUSTER_AWS_AZ} \
--master-size="t2.medium" \
--node-size="t2.medium" \
--node-count="2" \
--dns-zone=${DOMAIN_NAME} \
--ssh-public-key="~/.ssh/id_rsa.pub" \kops update cluster --name udagramk8s.kops.ucci.uk --yesIt will take approximately 5 minutes for the cluster to become availble, next we validate and check the status of the cluster by running the following command :
kops validate clusterCheck more if the cluster is ready :
kubectl get nodes...
Setup the account
...
Setup the environement variables from the Travis-CI console, under project > settings
Note execute cat ~/.kube/config to get the values
...
check the different scripts
../..
Remove the cluster
kops delete cluster --name=$CLUSTER_FULL_NAME --state=s3://${CLUSTER_FULL_NAME}-state --yesDestroy the ressources created by terraform
terraform destroyNote : The aim of this ReadMe file is just to give a general idea about how our kubernetes cluster and CI/CD environment are stood up

