Microservice | Description |
API gateway | It's a Spring Cloud Zuul-based gateway and the aggregated portal for calling backend APIs, providing reverse routing and load balancing (Eureka + Ribbon) as well as rate limiting (Hystrix). Client single-page applications and the Zuul gateway are deployed together to simplify deployment. |
Service registration and discovery | A Spring Cloud Eureka registry. Business services are registered through Eureka when they are enabled, and service discovery is performed through Eureka when services are called. |
Authorization and authentication service | An authorization and authentication center based on Spring Security OAuth2. The client gets the access token through the Auth Service during logins, and so does service call. Each resource server verifies the token through the Auth Service. |
Configuration service | A configuration center based on Spring Cloud Config to centrally manage configuration files for all Spring services. |
Soft loading and rate limiting | Ribbon and Hystrix based on Spring Cloud. Zuul calls backend services through Ribbon for soft loading and Hystrix for rate limiting. |
Metrics and dashboard | Hystrix Dashboard based on Spring Cloud Turbine, aggregating all the PiggyMetrics streams generated by Hystrix and displaying them on the Hystrix Dashboard. |
Network Planning | Description |
Region/AZ | Nanjing/Nanjing Zone 1 |
VPC | CIDR: 10.0.0.0/16 |
Subnet-Basic | Nanjing Zone 1, CIDR block: 10.0.1.0/24 |
Subnet-K8S | Nanjing Zone 1, CIDR block: 10.0.2.0/24 |
Nacos cluster | Nacos cluster built with three 1-core 2 GB MEM Standard SA2 CVM instances with IP addresses of 10.0.1.9, 10.0.1.14, and 10.0.1.15 |
Add-on | Version | Source | Remarks |
K8S | 1.8.4 | Tencent Cloud | TKE management mode |
MongoDB | 4.0 | Tencent Cloud | TencentDB for MongoDB WiredTiger engine |
CLS | N/A | Tencent Cloud | Log service |
TSW | N/A | Tencent Cloud | Accessed with SkyWalking 8.4.0 Agent, which can be downloaded here |
Java | 1.8 | Open-source community | Docker image of Java 8 JRE |
Spring Cloud | Finchley.RELEASE | Open-source community |
The storage layer can adapt to use cases with different data types, writing at the server layer, and query and reading requests at the data usage layer.
The data usage layer provides underlying support for console operations, data display, and alarming.
# Download the MongoDB client, decompress it, and enter the `bin` directory.wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.18.tgztar -zxvf mongodb-linux-x86_64-3.6.18.tgzcd mongodb-linux-x86_64-3.6.18/bin# Run the following command to initialize MongoDB, where `mongouser` is the admin account created when the MongoDB instance is created../mongo -u mongouser -p --authenticationDatabase "admin" [mongodb IP]/piggymetrics mongo-init.js
piggymetrics
library is created in the MongoDB initialization script mongo-init.js by default, which can be modified as needed. Subnet-K8S
(the ID of this CLB instance will be used later). account-service
as an example to describe how to write a Dockerfile. The project directory structure of account-service
is displayed, Dockerfile is in the root directory of the project, and account-service.jar is the packaged file that needs to be added to the image. ➜ account-service tree├── Dockerfile├── skywalking│ ├── account.config│ └── skywalking-agent.zip├── pom.xml├── src│ ....├── target│ .....│ └── account-service.jar└── account-service.iml
account-service
is as shown below:FROM java:8-jre# Working directory in the container/appWORKDIR /app# Add the locally packaged application to the image.ADD ./target/account-service.jar# Copy SkyWalking Agent to the image.COPY ./skywalking/skywalking-agent.zip# Decompress SkyWalking Agent and delete the original compressed file.RUN unzip skywalking-agent.zip && rm -f skywalking-agent.zip# Add the SkyWalking configuration file.COPY ./skywalking/account.config ./skywalking-agent/config/agent.config# Start the application.CMD ["java", "-Xmx256m", "-javaagent:/app/skywalking-agent/skywalking-agent.jar", "-jar", "/app/account-service.jar"]# Port description of the applicationEXPOSE 6000
ccr.ccs.tencentyun.com/[namespace]/[ImageName]:[image tag]
:namespace
can be the project name to facilitate image management and use. In this document, piggymetrics
represents all the images under the PiggyMetrics project. ImageName
can contain the subpath
, generally used for multi-project use cases of enterprise users. In addition, if a local image is already built, you can run the docker tag
command to rename the image in line with the naming convention.# Recommended build method, which eliminates the need for secondary tagging operationssudo docker build -t ccr.ccs.tencentyun.com/[namespace]/[ImageName]:[image tag]# Build a local `account-service` image. The last `.` indicates that the Dockerfile is stored in the current directory (`account-service`).➜ account-service docker build -t ccr.ccs.tencentyun.com/piggymetrics/account-service:1.0.0 .# Rename existing images in line with the naming conventionsudo docker tag [ImageId] ccr.ccs.tencentyun.com/[namespace]/[ImageName]:[image tag]
docker images | grep piggymetrics
piggymetrics
namespace in the pop-up window. All the images of the PiggyMetrics project are stored under this namespace as shown below:
docker login --username=[Tencent Cloud account ID] ccr.ccs.tencentyun.com
sudo
before the command and run it as shown below. In this case, you need to enter two passwords, the server admin password required for sudo
and the TCR login password.sudo docker login --username=[Tencent Cloud account ID] ccr.ccs.tencentyun.com
docker push ccr.ccs.tencentyun.com/[namespace]/[ImageName]:[image tag]
Private
. If you want to let others use the image, you can set it to Public
in Image Info as shown below:
piggyMetrics
.PiggyMetrics-k8s-demo
cluster to enter the Basic Info page to view the cluster configuration information. config
file under user home/.kube
(choose another if the config
file has content) to ensure that the default cluster can be accessed each time. If you choose not to store the token in the config
file under .kube
, see the Instructions on Connecting to Kubernetes Cluster via kubectl under Cluster API Server Info in the console as shown below:
kubectl create namespace piggymetrics
PiggyMetrics
.kubctl create –f namespace.yaml
namespace.yaml
is as shown below:# Create the `piggymetrics` namespace.apiVersion: v1kind: Namespacemetadata:name: piggymetricsspec:finalizers:- kubernetes
# Create a ConfigMap.apiVersion: v1kind: ConfigMapmetadata:name: piggymetrics-envnamespace: piggymetricsdata:# MongoDB IP addressMONGODB_HOST: 10.0.1.13# TSW access address as described belowSW_AGENT_COLLECTOR_BACKEND_SERVICES: ap-shanghai.tencentservicewatcher.com:11800
piggymetrics-env
for storing the configuration. The piggymetrics
namespace is as shown below:
value
of the Secret needs to be a Base64-encoded string.# Create a Secret.apiVersion: v1kind: Secretmetadata:name: piggymetrics-keysnamespace: piggymetricslabels:qcloud-app: piggymetrics-keysdata:# Replace `XXX` below with the actual value.MONGODB_USER: XXXMONGODB_PASSWORD: XXXSW_AGENT_AUTHENTICATION: XXXtype: Opaque
piggymetrics-keys
as shown below:config-server
:---kind: ServiceapiVersion: v1metadata:name: config-servernamespace: piggymetricsspec:clusterIP: Noneports:- name: httpport: 8888targetPort: 8888protocol: TCPselector:app: configversion: v1---apiVersion: apps/v1kind: StatefulSetmetadata:name: confignamespace: piggymetricslabels:app: configversion: v1spec:serviceName: "config-server"replicas: 1selector:matchLabels:app: configversion: v1template:metadata:labels:app: configversion: v1spec:terminationGracePeriodSeconds: 10containers:- name: configimage: ccr.ccs.tencentyun.com/piggymetrics/config-server:2.0.03ports:- containerPort: 8888protocol: TCP
account-service
Deployment are as follows:Parameter | Description |
replicas | Indicates the number of Pods to be created. |
image | Image address |
imagePullSecrets | The key to pull an image, which can be obtained from Cluster > Configuration Management > Secret. It is not required for public images. |
env | Defines Pod environment variables and values. The key-value defined in the ConfigMap can be referenced by using configMapKeyRef .The key-value defined in the Secret can be referenced by using secretKeyRef . |
ports | Specifies the port number of the container. It is 6000 for account-service . |
account-service
Deployment:# account-service DeploymentapiVersion: apps/v1kind: Deploymentmetadata:name: account-servicenamespace: piggymetricslabels:app: account-serviceversion: v1spec:replicas: 1selector:matchLabels:app: account-serviceversion: v1template:metadata:labels:app: account-serviceversion: v1spec:containers:- name: account-serviceimage: ccr.ccs.tencentyun.com/piggymetrics/account-service:1.0.1env:# MongoDB IP address- name: MONGODB_HOSTvalueFrom:configMapKeyRef:key: MONGODB_HOSTname: piggymetrics-envoptional: false# MongoDB username- name: MONGODB_USERvalueFrom:secretKeyRef:key: MONGODB_USERname: piggymetrics-keysoptional: false# MongoDB password- name: MONGODB_PASSWORDvalueFrom:secretKeyRef:key: MONGODB_PASSWORDname: piggymetrics-keysoptional: false# TSW access point- name: SW_AGENT_COLLECTOR_BACKEND_SERVICESvalueFrom:configMapKeyRef:key: SW_AGENT_COLLECTOR_BACKEND_SERVICESname: piggymetrics-envoptional: false# TSW access token- name: SW_AGENT_AUTHENTICATIONvalueFrom:secretKeyRef:key: SW_AGENT_AUTHENTICATIONname: piggymetrics-keysoptional: falseports:# Container port- containerPort: 6000protocol: TCPimagePullSecrets: # Token to pull the image- name: qcloudregistrykey
ServiceType
, which defaults to ClusterIP
. Valid values of ServiceType
include the following:ServiceType
is set to LoadBalancer
. TKE enriches the LoadBalancer
mode by configuring the Service through annotations. service.kubernetes.io/qcloud-loadbalancer-internal-subnetid
annotations, a private network CLB instance will be created when the Service is deployed. In general, we recommend you create the CLB instance in advance and use the service.kubernetes.io/loadbalance-id
annotations in the deployment YAML to improve the efficiency. gateway service
:# Deploy `gateway service`.apiVersion: v1kind: Servicemetadata:name: gatewaynamespace: piggymetricsannotations:# Replace it with the ID of the CLB instance of `Subnet-K8S`.service.kubernetes.io/loadbalance-id: lb-hfyt76cospec:externalTrafficPolicy: Clusterports:- name: httpport: 80targetPort: 4000protocol: TCPselector: # Map the backend `gateway` to the Service.app: gatewayversion: v1type: LoadBalancer
gateway service
VIP.piggymetrics
. piggymetrics-logs
.account-service
log collection. For more information on CRD collection configuration, see Using CRD to Configure Log Collection via YAML.apiVersion: cls.cloud.tencent.com/v1kind: LogConfigmetadata:name: account-log-rulespec:clsDetail:extractRule: {}# Single-line textlogType: minimalist_log# Log topic IDtopicId: 8438cc9b-888f-469f-9cff-9891270a0a13inputDetail:# Standard container outputcontainerStdout:container: account-serviceincludeLabels:app: account-serviceversion: v1namespace: piggymetricstype: container_stdout
collector.backend_service
and agent.authentication
respectively in the agent.config
of SkyWalking. agent.service_name
is the service name, and agent.namespace
can be used to group microservices under the same domain. account-service
configuration is as shown below:
SW_AGENT_COLLECTOR_BACKEND_SERVICES
.SW_AGENT_AUTHENTICATION
.account-service
responded too slowly and all statistic-service
requests failed in the past hour. statistics-service
to enter the information page. Click API Observation, and you can see that the API {PUT}/{accountName}
throws a NestedServletException
exception, which makes the API unavailable.
Apakah halaman ini membantu?