Go microservices architecture practice
Go Microservices architecture practice directory
1. Microservices Architecture part 1
1. GRPC technology introduction
GRPC + Protobuf + gateway actual combat
3. Etcd technology introduction
4. Etcd-based service discovery and registration
5. Distributed lock combat based on ETCD
2. Microservices Architecture
1. K8s architecture introduction
2. Container deployment based on K8S
Deployment workload based on K8S –
This is mainly implemented using Deployment resource objects and includes the following capabilities:
-
Copy more episodes
-
Enlarge shrinks capacity
-
Self-healing and failover
-
Scroll to update
-
The fallback capacity
Let’s take a closer look at the operation process
1. Multiple replica sets
Yaml simply changes the replicas to the number of copies we want.
apiVersion: apps/v1 kind: Deployment metadata: name: k8sdemo-deploy labels: app: k8sdemo spec: replicas: Selector: matchLabels: app: k8sdemo template: metadata: labels: app: k8sdemo spec: containers: - name: selector: matchLabels: app: k8sdemo spec: containers: k8sdemo image: k8s-grpc-demo:latest imagePullPolicy: Never ports: - containerPort: 50007Copy the code
thenkubectl apply -f deploy.yaml
Apply it and see the result:The results showed that the three pods were successful.
2. Enlarge shrinks
It’s a simple one line command:
kubectl scale --replicas=1 deployment/k8sdemo-deploy
Press Enter to print the following:
Kubectl get pod = kubectl get pod = kubectl get pod = kubectl
3. Self-healing and failover
Because I only have one machine, I can’t verify it, so I just list the steps, and you can try it yourself.
-
Stop a machine
-
Delete a POD
Try it out and see if the POD will come up again on another machine, keeping the number of replica sets in the Deployment the same. Or after a POD is removed from a machine, see if the pod is re-established (thanks to Deployment’s capabilities).
Tips: If you want to delete the POD and it persists, the POD will start automatically. Don’t worry, you should delete the Deployment first, then the POD will be deleted automatically.
4. Rolling updates
First you make some updates based on your code, such as adding logging and other features. Then you build a local image, such as K8S-grpc-demo :v2. Then you can roll the update with a single command:
kubectl set image deployment/k8sdemo-deploy k8s-grpc-demo=k8s-grpc-demo:v2 --record
Copy the code
Check the update status
kubectl rollout status deployment/k8sdemo-deploy
Copy the code
5. Rollback capability
- View historical version records
kubectl rollout history deployment/k8sdemo-deploy
Copy the code
- View a historical detail
kubectl rollout history deployment/k8sdemo-deploy --revision=2
Copy the code
- Rollback (back to last time)
kubectl rollout undo deployment/k8sdemo-deploy
Copy the code
- Rollback (back to the specified version)
kubectl rollout undo deploymen/k8sdemo-deploy --to-revision=2
Copy the code
6. Summary
In fact, THE use of K8S is not very complex, you can learn k8S after building their own services, but if you want to further customize K8S, need to have a certain golang knowledge and container knowledge, so want to further study the source code to understand the principle.
The next article will continue to explain the service registration and discovery capabilities of K8S service and the gateway capabilities of ingress, as well as their network architecture knowledge. If you like this article, please follow, forward and share.
Github address: github.com/guojiangli/…
Public reed id: Stack Future
So that a lot of confused stage coder can find the light from here, stack creation, achievement in the contemporary, future benefits
Public reed id: Stack Future