Cloud native architecture

Cloud native architecture

1. Docker

1.1 Mirror warehouse

docker hub

1.2 Mirror operation

Download: docker pull image (nginx, redis)

Direct download is the latest version of the tool, and you can specify the version through the image name: version.

Delete: docker rmi image name: version number (default lastest)/image id

1.3 Container operations
1.3.1 Run the image:

docker run [options] images [command]

  • docker run setting item image name startup command (default, generally not configured)
    • –name=xxx Container name after execution
    • -d runs in the background
    • -p public network port: port in the container
    • -v external: internal files are mounted inside the container to files in the external linux system
    • –restart=always will restart automatically every time you boot
1.3.2 Operating containers

If it is not specified the first time, you can update the setting items through docker update container id --restart = always.

But docker update cannot modify the port of the container.

  • docker ps to view running containers

  • docker rm container name/container id You can use -f to forcefully delete the running container

  • docker stop container id stops the running container

  • docker start container id

1.3.3 Manipulate files inside the container

docker exec -it container id /bin/bash (console) -it operates in interactive mode

Enter the container (small nginx) and modify the container file

1.3.4 Commit container changes

Local: docker commit -a "Author" -m "Describe the submitted content" container id new image name.

Remote: Import an image from one computer to another:

1.docker save -o xxx.tar Image name: version Compress the image into a compressed package (you can use the load -i command to decompress the package into an image)

If you directly use the image ID to package, the image name after decompression will be none . You can use docker tag image ID xxx: version.

scp xxx.tar [email protected] sends the compressed package to a host

2. Push the image to the remote warehouse

  • Register docker hub to create repository
  • docker tag localimage:localtag new-repo:tagname
  • docker push new-repo:tagname
  • You need to log in to docker login before pushing
  • After the push is completed, other machines only need docker pull.
1.3.5 How to use docker to deploy a Java project

1. Install related images (redis)

2. Package the java project into a jar package

3. Write a Dockerfile to package our Java project into an image (docker build -t xxxdemo:vxx .)

4.docker run runs the java project image

2. Kubernetes

Insert image description here

The environment between containers is isolated and will not affect the operation of other containers, which solves the problem of cumbersome virtual machines. However, containers are difficult to manage, so K8S is used to manage and orchestrate containers.

K8s is a framework that can run distributed systems flexibly. Advantages:

  • Service discovery and load balancing
  • Memory orchestration, allocation and recycling of application memory.
  • Automatic deployment and rollback capabilities
  • Automatic boxing calculations, allowing you to specify the memory and CPU required for each container
  • Self-healing (an application crashes on one machine and will be automatically deployed to other machines)
  • Configuration management
2.1 Architecture
2.1.1 Working method

N master nodes + N nodes
Insert image description here
Insert image description here
All working nodes communicate with the master node through api-service, and external access to working nodes requires kube-proxy. The kubelet will monitor the container activity status within the node in real time. If a problem is found, the decision maker will be notified through the api-server in a timely manner. All node data is stored in ETCD (similar to Redis).

2.2 Cluster deployment

kubelet: node manager.

kubectl:k8s console for programmers to use

kubeadm: manages k8s nodes, making it easier to manage nodes. You can specify a node as the master node through kubeadm init. Later, kubelet will create the required components (download image) of the master node: scheduler (scheduler, agent, api-server, etcd, etc.), and other nodes can join this cluster as working nodes through kubeadm join.

Guess you like

Origin blog.csdn.net/qq_50876039/article/details/132953883