Kubernetes + vagrant + docker = HA ?
Divers
OLD STUFF, NOT FINISHED, nowdays Kubernetes has a real HA…
On your machine boot up a vagrant environment that will manage the whole operations (repeatable environment) :
1 2 |
vagrant init ubuntu/xenial64 vagrant up |
now just ssh into your vagrant box (for windows user use puttygen to get a ppk file from the private key generated)
To know where everything is set-up :
1 |
vagrant ssh-config |
Once on your vagrant machine, update your repo
1 |
sudo apt-get update |
Install kops
1 2 3 |
wget -c https://github.com/kubernetes/kops/releases/download/1.5.2-beta.2/kops-linux-amd64 chmod +x kops-linux-amd64 sudo mv kops-linux-amd64 /usr/local/bin/kops |
Install python and pip as amazonws client is in python
1 2 3 4 |
sudo apt-get install -y python-pip pip install --upgrade pip sudo pip install awscli aws |
AWS client is functionnal
Go on AWS create an account if you don’t have one, then add a user named “kops” and add it into the group Administrators.
Note the id key and secret key as they will be asked now :
1 |
aws configure |
Go into S3 and create a bucket (mine is named xolkys-kops-state-01)
Go into Route53 and declare a subdomain, modify your DNS accordingly (mine is kubernetes.quidquid.fr)
Install kubectl
1 2 3 4 |
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 kubectl |
Generate a private/public key (or use one you already have) :
1 2 |
ssh-keygen -f .ssh/id_rsa cat .ssh/id_rsa.pub |
Now we create a cluster with a master and 2 nodes :
1 |
kops create cluster --name=kubernetes.quidquid.fr --state=s3://xolkys-kops-state-01 --zones=eu-central-1a --node-count=2 --node-size=t2.micro --master-size=t2.micro --dns-zone=kubernetes.quidquid.fr |
Nothing is done now, just a file, you can edit it :
1 |
kops edit cluster kubernetes.quidquid.fr --state=s3://xolkys-kops-state-01 |
And now we ask for real modifications :
1 2 3 |
kops update cluster kubernetes.quidquid.fr --yes --state=s3://xolkys-kops-state-01 cat .kube/config |
Wait a few minutes and launch this command to see if everything is ok, you can go to your AWS console to see your EC2 instances in action :
1 |
kubectl get node |
Run a docker image in our cluster :
1 |
kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080 |
Open the cluster to the outside world :
1 2 |
kubectl expose deployment hello-minikube --type=NodePort kubectl get service |
Note the port and open INBOUND traffic in security group in AWS
If you want to delete everything you did (except for Route53) :
1 2 |
kops delete cluster --name kubernetes.quidquid.fr --state=s3://xolkys-kops-state-01 kops delete cluster --name kubernetes.quidquid.fr --state=s3://xolkys-kops-state-01 --yes |
Now install docker :
1 2 |
sudo apt-get update sudo apt-get -y install docker.io |
Add user ubuntu into docker group :
1 |
sudo usermod -G docker ubuntu |
To build an docker image :
docker build
docker run -p 3000:3000
docker ps
docker stop
login to docker
docker login
docker tag /docker-test
or
docker build -t /docker-test
docker push /docker-test
Leave a comment