-
install kubectl --> https://kubernetes.io/docs/tasks/tools/install-kubectl/
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
-
install Kops
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
chmod +x ./kops
sudo mv ./kops /usr/local/bin/
-
install AWS CLI
apt-get update
install -y awscli
Then do as the following https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
- configure the awscli using your AWS account "you could create free account"
aws configure
Note : the AWS user must have adminstration permission
- create new S3 bucket to save your KOPS state "it has to be at the same KOPS region"
A. make sure that it works "ex: bucket name k8s-kops-berlin-zeineldin"
aws s3 mb s3://k8s-kops-berlin-zeineldin
B. Enable bucker versioning
aws s3api put-bucket-versioning --bucket k8s-kops-berlin-zeineldin --versioning-configuration Status=Enabled
C. Expose ENV "to save the state of the Cluster"
export KOPS_STATE_STORE=s3://k8s-kops-berlin-zeineldin
- Create DNS Configurations
kubernetes uses DNS for discovery inside the cluster so that you can reach out kubernetes API server from clients. create a hosted zone on Route53, say, k8s.devops.vpc. The API server endpoint will then be ex:berlin.k8s.local as (Gossip DNS)
-
Create ssh public and private keys
ssh-keygen
it will be created in the default location which is ~/.ssh/id_rsa.pub
-
export cluster and bucket name
export KOPS_CLUSTER_NAME=cluster.zeinedin.local
-
create KOPS Cluster
kops create cluster --name=${KOPS_CLUSTER_NAME} --ssh-public-key="~/.ssh/id_rsa.pub" --state=${KOPS_STATE_STORE} --zones=eu-west-1a --master-size=t2.micro --node-count=2 --node-size=t2.micro
Note : if you don't have DNS configuration you could just use gossip based DNS "ie: zein.cluster.k8s.local""
kops create cluster --name=${KOPS_CLUSTER_NAME} --ssh-public-key="~/.ssh/id_rsa.pub" --state=${KOPS_STATE_STORE} --zones=eu-west-1a --master-size=t2.micro --node-count=2 --node-size=t2.micro --topology=private --networking=calico
-
You could edit in the cluster
kops edit cluster --name ${KOPS_CLUSTER_NAME}
-
Run the Cluster
kops update cluster --name ${KOPS_CLUSTER_NAME} --yes
-
Make Sure that every thing works
kops validate cluster
-
login to the master server and check the cluster
ssh -i ~/.ssh/id_rsa admin@<Mater_Node_IP>
-
Create the 1st deployment
kubectl run webserver --image=nginx --port= 80 -- replicas=2
-
Export the deployment
kubectl expose deployment webserver --name web-service --type=LoadBalancer --port=80
-
check the service
kubectl get service
check the port
-
Open the port in the KOPS Cluster Security group
-
SEE THE SERVICE FROM THE URL:PORT
-
delete the culster if you want :)
kops delete cluster --name ${CLUSTER_NAME} --yes