December 04, 2016
We will setup a small cluster of 3 n1-standard-1 instances. They cost around $25 per month. So the cluster will cost you somewhere above $75 a month for the servers.
This is just a few notes from the tutorial from kubernetes.io.
brew cask install google-cloud-sdk
Go to console.cloud.google.com and set it up. Remember the project id.
Install kubectl
gcloud components install kubectl
Have a sample project.
In a server.js
file
var http = require('http');
var handleRequest = function(request, response) {
console.log('Received request for URL: ' + request.url);
response.writeHead(200);
response.end('Hello World!');
};
var www = http.createServer(handleRequest);
www.listen(8080);
Dockerfile
FROM node:4.4
EXPOSE 8080
COPY server.js .
CMD node server.js
docker build -t gcr.io/$PROJECT_ID/hello-node:v1 .
gcloud auth login
gcloud config set project PROJECT_ID
gcloud docker -- push gcr.io/$PROJECT_ID/hello-node:v1
gcloud container clusters create hello-world
Fetch configuration needed
gcloud container clusters get-credentials hello-world
I had some missing credentials. Had to run this command again:
gcloud auth application-default login
kubectl run hello-node --image=gcr.io/$PROJECT_ID/hello-node:v1 --port=8080
Allow external traffic to the application
kubectl expose deployment hello-node --type="LoadBalancer"
To find the ip adress run:
kubectl get services hello-node
You can now see your service running on you kube cluster.
kubectl get deployments
kubectl get pods
kubectl logs
kubectl cluster-info
kubectl get events
kubectl config view
kubectl get services hello-node
Run kubectl cluser-info
and you will see a list of all Kubernetes services running. One is the Kubernetes-Dashboard
.
If you open that url in the browser you will be prompted for a username and password. These can we viewed (in plain text) with:
gcloud container clusters describe
Somewhere in there you will find a username
and password
.
Scale up? Or scale down? Define how many instance you want to have running and the rest is managed for you.
kubectl scale deployment hello-node --replicas=4
Modify you application.
docker build -t gcr.io/$PROJECT_ID/hello-node:v2 .
gcloud docker push gcr.io/$PROJECT_ID/hello-node:v2
To run the new version we set which image we want kube to run.
kubectl set image deployment/hello-node hello-node=gcr.io/$PROJECT_ID/hello-node:v2
If you did this to test it out you might want to remove your cluster now.
kubectl delete service,deployment hello-node
gcloud container clusters delete hello-world
List all the images you uploaded
gsutil ls
Remove them:
gsutil rm -r gs://artifacts.$PROJECT_ID.appspot.com/
That it.
Written by Simon Ström as a way to remember. It's a dev log of thinks I want to remember.