what we are going to do? we will build an app completely scalable vertically and horizontally on top of a workflow managed by GCP using a kubernetes infrastructure design, so get tighten your belts and enjoy the learning situation.
There are a things you need to have configured in your machine to get the commands going right.
Resume of all ours steps, we will:
- Create a Cluster and a Node
- Create a k8s infrastructure
- Versioned we have a Dockerfile sample
- Versioned we have an APP sample
- Build a Workflow
[k8s][GCP]Create a namespace for our test project
kubectl create namespace k8s-v1-admin
[GCP]auto scalling vertical
gcloud container clusters create k8s-v1-admin --labels=environment=production,v=1,operator=mesaquesilva --min-nodes=2 --max-nodes=13 --enable-autoscaling --node-labels=environment=production
[k8s]creating a controller
kubectl --namespace=k8s-v1-admin create -f k8s/deployment/admin-prod.yaml
[k8s]creating a service
kubectl --namespace=k8s-v1-admin create -f k8s/service/admin-prod.yaml
[k8s]scalling / horizontal (manual / automatic)
kubectl --namespace=k8s-v1-admin scale deployment/admin --replicas=6
kubectl --namespace=k8s-v1-admin autoscale deployment/admin --min=1 --max=15
[k8s]deploy/update image ( when editing change the commit hash )
kubectl --namespace=k8s-v1-admin edit deployment/admin
list context
kubectl config get-contexts
change context from GCP to minikube
kubectl config use-context minikube
[k8s][minikube]Create namespace for our test project
kubectl create namespace k8s-v1-admin
- Go to “IAM & Admin” section of the Google Cloud Console and select “Service Accounts”. Then click the “Create Service Account” button
- select the option to “Furnish a new private key” with the “JSON” key type.
- in role / papel select: roles/storage.objectViewer
Dont forget of change in this string where are you json key and mail
- RUN:
kubectl --namespace=k8s-v1-admin create secret docker-registry gcr-json-key \
--docker-server=https://gcr.io \
--docker-username=_json_key \
--docker-password="$(cat ~/Downloads/somekey.json)" \
--docker-email=somemail@somehost.com
- RUN:
kubectl --namespace=k8s-v1-admin patch serviceaccount default \
-p '{"imagePullSecrets": [{"name": "gcr-json-key"}]}'
- Now you have access to your gcr images
kubectl --namespace=k8s-v1-admin create -f k8s/deployment/admin-prod.yaml
kubectl --namespace=k8s-v1-admin create -f k8s/service/admin-prod.yaml
get minikube project access url minikube --namespace=k8s-v1-admin service admin --url
list pods (gcp|minikube)
kubectl --namespace=k8s-v1-admin get pods
list services
kubectl --namespace=k8s-v1-admin get services
list deployments
kubectl --namespace=k8s-v1-admin get deployments