Microservice - Deploy with K8s (2)
MicroService Deployment with Docker + Kubernetes + Skaffold
This one is pretty long but very helpful to understand what is going on with Kubernetes and how different pods get connected with each other!
The banner image is Dao Cheng (稻城), which is a famous natural reserve in Sichuan province. I have never been there but always heard it. I have to say that Sichuan province is gifted as it has so many natural sceneries that cannot be missed. Really wish to visit there after I back there! btw, really missing Sichuan hometown food~~
¶Microservice - Deployment
¶Kubernetes + Docker
We will have a common message channel that routes events to each node separately!
minikube start --vm=true
minikube start --driver=hyperv
minikube start --driver=virtualbox
Service is a general API that handle access to a running container
kubectl apply -f posts.yaml
Deployment controls a set of same-type pods for updating, re-creating new pods…etc
¶Update - Make Change to Deployment
Between each pod, Service is used to communicate between each other
Service is used as a general API of the pods.
- Within each pod, we use Cluster IP
- In the Dev stage, we can use the port to connect with the web browser
- In the Prod stage, Load Balancer is used
For now, we use Node Port for fun
nodePort is a randomly assigned port to access the service outside of the
One type of pod will get one service
To communicate from Event-Bus to another pod, we are basically communicating from
cluster is a set of same-type
¶A general procedure of creating a deployment+service
- Build an image for the Service ( event bus, in this step)
- Push the image to Docker Hub
- Create a deployment for Event Bus
- Create a cluster IP service for event bus and posts
- Wire them up
We can write
deployment config and
service config in one config file
type: ClusterIP in
spec will be the default
ClusterIp service is setted up, it can directly communicate within cluster with
This finishes our last step of wiring up.
We then do the similar steps from
- Build container image
- Create deployment file
kubectl apply -f .
- wire them in
kubectl rollout restart deployment <name>if need
¶Load Balancer - Nginx/ Ingress
Load Balancer Service: A config file for a LoadBalancer Service is to let Cloud platform provision a Load Balancer outside of a cluster so that traffic can be routed into cluster.
Ingress: A pod with a set of routing rules to distribute traffic to other services
Nginx ingress controller uses LoadBalancer type service actually as entrypoint to the cluster. Then is checks ingress rules and distributes the load.
As the process of deploying app so annoying, we can use this tool to expedite our development.
- The way of interactions between micro-services is by HTTP requests (or we can use gRPC in future.
- Each service will send event to
Event Bus, which is pretty similar to how REDUX works.
- Each service will have a event listener as well.
- Each service will need
ClusterIP Serviceto communicate within a cluster.
ingress-nginxpod is created to match different routes to specific ports based on route rules. (through nginx)
LoadBalancer typeService is automatically initialized with
ingress-nginx. It is solely responsible to communicate with
- Skaffold is able to detech changes made inside source files by connecting
depl.yml, Dockerfile, skaffold.ymlNote that we need to use
nodemon, star:devto allow for hot reload.
本博客所有文章除特别声明外，均采用 CC BY-SA 4.0 协议 ，转载请注明出处！