In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how the raspberry pie K8s cluster deploys the spring cloud microservice project. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Introduction to spring cloud
Spring cloud is one of the current mainstream micro-service frameworks. Although the official spring-cloud-kubernetes open source project has been launched to make Spring Cloud applications more convenient to run in the kubernetes environment, considering that some spring cloud projects are still based on non-K8s environment, once migrated to K8s environment need to retain the original architecture as much as possible, so this project still uses eureka as the service registration discovery component and spring-cloud-config as the configuration center.
Installation preparation
Raspberry pie k8s cluster
Root@pi4-master01:~# kubectl get nodes-o wideNAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIMEpi4-master01 Ready master 4d18h v1.15.10 192.168.5.18 Ubuntu 20.04 LTS 5.4.0-1011-raspi docker://18.9.9pi4-node01 Ready node 4d17h v1.15.10 192.168.5.19 Ubuntu 20.04 LTS 5.4.0-1011-raspi docker://18.9.9pi4-node02 Ready node 4d17h v1.15.10 192.168.5.20 Ubuntu 20.04 LTS 5.4.0-1011-raspi docker://18.9.9
Raspberry pie K8s cluster has installed helm
Root@pi4-master01:~/k8s/cluster-monitoring-0.37.0# helm versionClient: & version.Version {SemVer: "v2.15.0", GitCommit: "c2440264ca6c078a06e088a838b0476d2fc14750", GitTreeState: "clean"} Server: & version.Version {SemVer: "v2.15.0+unreleased", GitCommit: "9668ad4d90c5e95bd520e58e7387607be6b63bb6", GitTreeState: "dirty"}
By the way, if you don't already have a raspberry pie K8s cluster, here is a raspberry pie K8s cluster entry guide for reference. Welcome to join us.
Spring cloud sample project image
The following is the image used in this practice, its source code and Dockerfile in https://gitee.com/pi4k8s/springcloud-simple.git, the specific code will not be introduced, interested students can adjust themselves.
Call chain View system (zipkin-server): pi4k8s/spring-cloud-zipkin:0.0.1
Service Discovery Registry (eureka): pi4k8s/spring-cloud-eureka:0.0.1
Configuration Center (config-server): pi4k8s/spring-cloud-config-server:0.0.1
Aggregate Circuit Breaker Panel (hystrix-dashboard): pi4k8s/spring-cloud-hystrix-dashboard:0.0.1
Sample component of service provision (provider): pi4k8s/spring-cloud-provider:0.0.1
Service consumption sample component (consumer): pi4k8s/spring-cloud-consumer:0.0.1
Server Gateway (gateway): pi4k8s/spring-cloud-gateway:0.0.1
Spring cloud sample project chart
Call chain View system (zipkin-server): https://github.com/pi4k8s/pi4charts/tree/master/springcloud-example/charts/zipkin-server
Service Discovery Registry (eureka): https://github.com/pi4k8s/pi4charts/tree/master/springcloud-example/charts/eureka
Configuration Center (config-server): https://github.com/pi4k8s/pi4charts/tree/master/springcloud-example/charts/config-server
Sample component of service provision (provider): https://github.com/pi4k8s/pi4charts/tree/master/springcloud-example/charts/provider
Service consumption sample component (consumer): https://github.com/pi4k8s/pi4charts/tree/master/springcloud-example/charts/consumer
Aggregate circuit breaker panel (hystrix-dashboard): https://github.com/pi4k8s/pi4charts/tree/master/springcloud-example/charts/hystrix-dashboard
Server Gateway (gateway): https://github.com/pi4k8s/pi4charts/tree/master/springcloud-example/charts/gateway
Helm deployment spring cloud sample project
Our previous example articles are basically about how to use off-the-shelf chart to install an application, such as msyql, redis, kafka and consul. Today we choose to write chart from scratch and install the spring cloud sample project with this chart.
Helm's official home page shows helm's definition of "the package manager for kubernetes" and further explanation of "Helm is the best way to find, share, and use software built for Kubernetes.", translated into Chinese as "kubernetes's application manager" and "Helm is the best way to discover, share and use applications built for kubernetes". Generally speaking, the application built for kubernetes can basically be regarded as cloud native application, because it at least conforms to the three earliest definitions of cloud native in CNCF2015 year: containerization, micro-service-oriented architecture and supporting container orchestration and scheduling. From this we can see the confidence and strength that helm has shown in the cloud native field, no doubt, because we can easily install many applications we need based on various chart repositories. But if you really don't find a ready-made one, it doesn't matter. You can define and install it yourself with helm syntax. Once you do, you will find that it is so simple and natural to use helm to organize and define applications. The infrastructure architecture for containerized environment allows you to stop worrying about server configuration, network configuration and specific software installation details, and only need to pay attention to how the application modules are divided. How the relationship between modules can interact. The software architecture view based on helm chart can fully cover the physical view of traditional software architecture, and the content is even richer and more scalable than them.
We write our own spring cloud sample project chart here: https://github.com/pi4k8s/pi4charts/tree/master/springcloud-example/
Helm deployment call chain View system (zipkin-server)
The command to deploy zipkin-server using helm is as follows
Root@pi4-master01:/home/charts# git clone https://github.com/pi4k8s/pi4charts.gitroot@pi4-master01:/home/charts# cd pi4charts/springcloud-example/chartsroot@pi4-master01:/home/charts/pi4charts/springcloud-example/charts# helm install-n zipkin-server. / zipkin-server-- set ingress.enabled=true
With the above command, the configuration center zipkin-server will be deployed in Kubernetes. This command will install and deploy 1 zipkin-server node and open ingress access.
View the created pod
Root@pi4-master01:~# kubectl get po | grep zipkin-serverzipkin-server-0 1bat 1 Running 0 82s
View the created svc
Root@pi4-master01:~# kubectl get svc | grep zipkin-serverzipkin-server ClusterIP 10.99.240.173 9411/TCP 92s
View the created ingress
Root@pi4-master01:~# kubectl get ingress | grep zipkin-serverzipkin-server zipkin-server.pi4k8s.com 80 104s
Access the zipkin-server interface
Access http://zipkin-server.pi4k8s.com/ with a browser, which is displayed as follows
However, there is no requested data in the system yet.
Note: before using the browser to access the zipkin-server interface, you should refer to the following ip domain name mapping process for client settings.
Ip domain name mapping processing
Before accessing the system involved in this practice through a browser, we need to establish a mapping relationship between ip and related domain names when using the client to access the computer, similar to the following. Subsequent eureka, gateway and hystrix-dashboard all need to be set up. Refer to the settings in this paragraph and will not repeat them:
192.168.5.18 zipkin-server.pi4k8s.com
Tip: the file location for maintaining ip and related domain names on win10 or win7 computers is C:\ Windows\ System32\ drivers\ etc\ hosts.
Helm deployment Services Discovery Registry (eureka)
The command to deploy an eureka cluster using helm is as follows
Root@pi4-master01:/home/charts# git clone https://github.com/pi4k8s/pi4charts.gitroot@pi4-master01:/home/charts# cd pi4charts/springcloud-example/chartsroot@pi4-master01:/home/charts/pi4charts/springcloud-example/charts# helm install-n eureka. / eureka-- set ingress.enabled=true
With the above command, the eureka cluster will be deployed in Kubernetes. This command will install and deploy 3 eureka nodes and open ingress access.
View the created pod
Root@pi4-master01:~# kubectl get po | grep eurekaeureka-0 0 31seureka-1 1 Running 0 31seureka-2 0 Running 0 31seureka-2 0 Running 0 31s
View the created svc
Root@pi4-master01:~# kubectl get svc | grep eurekaeureka ClusterIP None 8080/TCP 79s
View the created ingress
Root@pi4-master01:~# kubectl get ingress | grep eurekaeureka eureka.pi4k8s.com 8089s
Access the eureka management interface
Visit http://eureka.pi4k8s.com/ and the page appears as follows
Helm deployment configuration Center (config-server)
The command to deploy config-server using helm is as follows
Root@pi4-master01:/home/charts# git clone https://github.com/pi4k8s/pi4charts.gitroot@pi4-master01:/home/charts# cd pi4charts/springcloud-example/chartsroot@pi4-master01:/home/charts/pi4charts/springcloud-example/charts# helm install-n config-server. / config-server\-- set service.type=NodePort\-- set service.nodePort=8001
With the above command, the configuration center config-server will be deployed in Kubernetes. By default, service.type is of ClusterIP type, and only supports internal access of K8s cluster. The example command modifies servcie.type to NodePort, and specifies an open port of 8001, which makes it easy for us to view the effect directly from the client through the browser.
View the created pod
Root@pi4-master01:~# kubectl get po | grep config-serverconfig-server-5896754dfc-t5sfl 1 grep config-serverconfig-server-5896754dfc-t5sfl 1 Running 0 6m4s
View the created svc
Root@pi4-master01:~# kubectl get svc | grep config-serverconfig-server NodePort 10.104.0.119 8001:8001/TCP 6m27s
Access the eureka management interface
When we visit http://eureka.pi4k8s.com/, we can notice that the configuration center has registered with eureka as follows
Use nodeport to access the configuration information of the configuration center
Visit http://192.168.5.18:8001/config/dev and the display is as follows
Helm deployment Services provides sample components (provider)
The command to deploy provider using helm is as follows
Root@pi4-master01:/home/charts# git clone https://github.com/pi4k8s/pi4charts.gitroot@pi4-master01:/home/charts# cd pi4charts/springcloud-example/chartsroot@pi4-master01:/home/charts/pi4charts/springcloud-example/charts# helm install-n provider. / provider\-- set service.type=NodePort\-- set service.nodePort=8007
With the above command, the service provider sample component, provider, will be deployed in kubernetes. By default, service.type is of ClusterIP type, and only supports internal access of K8s cluster. The example command modifies servcie.type to NodePort, and specifies an open port of 8007, which makes it easy for us to view the effect directly from the client through the browser.
View the created pod
Root@pi4-master01:~# kubectl get po | grep providerprovider-6f7ddcdf98-c9hxd 1bat 1 Running 0 33s
View the created svc
Root@pi4-master01:~# kubectl get svc | grep providerprovider NodePort 10.96.156.37 8007:8007/TCP 4m30s
Access the eureka management interface
Visiting http://eureka.pi4k8s.com/, we can notice that provider has registered with eureka as follows
Use nodeport to access the sample interface of provider
The provider component provides only two interfaces, of which the from interface invokes the data from the configuration center.
Visit http://192.168.5.18:8007/hello and the display is as follows
Visit http://192.168.5.18:8007/from and the display is as follows
Access the zipkin-server interface
Provider not only accesses the configuration center, but also accesses the call chain system, and accesses http://zipkin-server.pi4k8s.com/. You can find the following information about the access of the call chain
Helm deployment Services consumption sample component (consumer)
The command to deploy consumer using helm is as follows
Root@pi4-master01:/home/charts# git clone https://github.com/pi4k8s/pi4charts.gitroot@pi4-master01:/home/charts# cd pi4charts/springcloud-example/chartsroot@pi4-master01:/home/charts/pi4charts/springcloud-example/charts# helm install-n consumer. / consumer\-- set service.type=NodePort\-- set service.nodePort=9000
With the above command, the service consumption sample component, consumer, will be deployed in Kubernetes. By default, service.type is of ClusterIP type, and only supports internal access of K8s cluster. The example command modifies servcie.type to NodePort, and specifies an open port of 9000, which makes it easy for us to view the effect directly from the client through the browser.
View the created pod
Root@pi4-master01:~# kubectl get po | grep consumerconsumer-797656455-x2cgv 0bat 1 Running 2 19m
View the created svc
Root@pi4-master01:~# kubectl get svc | grep consumerconsumer NodePort 10.96.219.125 9000:9000/TCP 20m
Access the eureka management interface
Visiting http://eureka.pi4k8s.com/, we can notice that consumer has registered with eureka as follows
Use nodeport to access the sample interface of consumer
Visit http://192.168.5.18:9000/hello and the display is as follows
Access the zipkin-server interface
Consumer connects to the call chain system and accesses http://zipkin-server.pi4k8s.com/. You can check the relevant call chain access as follows
Access the hystrix-dashboard interface
Consumer is configured with a circuit breaker panel that can be displayed independently. Visit http://192.168.5.18:9000/hystrix, as shown below.
Enter http://192.168.5.18:9000/actuator/hystrix.stream in the text box of the interface, and then click the "Monitor Stream" button, which is displayed as follows
Helm deployment aggregation Circuit Breaker Panel (hystrix-dashboard)
The command to deploy hystrix-dashboard using helm is as follows
Root@pi4-master01:/home/charts# git clone https://github.com/pi4k8s/pi4charts.gitroot@pi4-master01:/home/charts# cd pi4charts/springcloud-example/chartsroot@pi4-master01:/home/charts/pi4charts/springcloud-example/charts# helm install-n hystrix-dashboard. / hystrix-dashboard-- set ingress.enabled=true
With the above command, the circuit breaker panel hystrix-dashboard will be deployed in Kubernetes. This command will install and deploy 1 hystrix-dashboard node and open ingress access, which currently aggregates only the consumer cluster circuit breaker panel.
View the created pod
Root@pi4-master01:~# kubectl get po | grep hystrix-dashboardhystrix-dashboard-6fd9b87589-65g89 0amp 1 Running 1 2m50s
View the created svc
Root@pi4-master01:~# kubectl get svc | grep hystrix-dashboardhystrix-dashboard ClusterIP 10.106.100.154 9902/TCP 18m
View the created ingress
Root@pi4-master01:~# kubectl get ingress | grep hystrix-dashboardhystrix-dashboard hystrix-dashboard.pi4k8s.com 80 18m
Access the eureka management interface
Visiting http://eureka.pi4k8s.com/, we can notice that hystrix-dashboard has registered with eureka as follows
Access the hystrix-dashboard interface
Visit http://hystrix-dashboard.pi4k8s.com/hystrix and the display is as follows
Enter http://hystrix-dashboard:9902/turbine.stream in the text box of the interface, and then click the "Monitor Stream" button to enter the aggregation monitoring page, which is displayed as follows
We will see the effect after the consumer is scaled to 3.
Root@pi4-master01:~# kubectl scale-replicas=3 deployment/consumerdeployment.extensions/consumer scaled
Confirm that consumer started 3 nodes successfully
Root@pi4-master01:~# kubectl get po | grep consumerconsumer-797656455-hsssp 1 11mconsumer-797656455-wq67x 1 Running 0 11mconsumer-797656455-wq67x 1 Running 0 86sconsumer-797656455-x2cgv 1 Running 0 28m
Visiting http://eureka.pi4k8s.com/, we can notice that consumer has registered three nodes with eureka as follows
Refresh the aggregation monitoring page to display the following
You can see that Hosts becomes 3.
Helm deployment Server Gateway (gateway)
The command to deploy gateway using helm is as follows
Root@pi4-master01:/home/charts# git clone https://github.com/pi4k8s/pi4charts.gitroot@pi4-master01:/home/charts# cd pi4charts/springcloud-example/chartsroot@pi4-master01:/home/charts/pi4charts/springcloud-example/charts# helm install-n gateway. / gateway-- set ingress.enabled=true
With the above command, the server gateway gateway will be deployed in kubernetes. This command will install and deploy 1 gateway node and open ingress access.
View the created pod
Root@pi4-master01:~# kubectl get po | grep gatewaygateway-69b9d7fb87-9zgz9 1 9zgz9 1 Running 0 86s
View the created svc
Root@pi4-master01:~# kubectl get svc | grep gatewaygateway ClusterIP 10.103.12.68 8220/TCP 3m57s
View the created ingress
Root@pi4-master01:~# kubectl get ingress | grep gatewaygateway gateway.pi4k8s.com 80 4m3s
Access the eureka management interface
Visiting http://eureka.pi4k8s.com/, we can notice that gateway has registered with eureka as follows
Gateway-based interface for accessing provider and consumer
The gateway configuration here is very simple, through which all services registered with the same eureka cluster can be proxied. Based on the gateway, we can access 2 interfaces of provider and 1 interface of consumer to see the effect.
Visit http://gateway.pi4k8s.com/provider/hello and the display is as follows
Visit http://gateway.pi4k8s.com/provider/from and the display is as follows
Visit http://gateway.pi4k8s.com/consumer/hello and the display is as follows
Thank you for reading! This is the end of the article on "Raspberry pie K8s cluster how to deploy spring cloud microservice project". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.