Enhancing Communication in Microservices with Linkerd
Written on
Linkerd serves as a powerful solution to address the communication difficulties often encountered in microservices architectures. Sponsored by the Cloud Native Computing Foundation (CNCF), Linkerd offers a variety of essential features for modern microservice environments.
If you're reading this, you likely recognize the complexities that come with adopting a microservices architecture. You may be exploring these challenges theoretically or experiencing them firsthand.
One of the prevalent issues is the network and communication between various components. As cloud-native developments evolve and expand, the necessity for new functionalities has shifted from being optional to essential.
Key concepts such as service discovery, service authentication, dynamic routing policies, and circuit breaker patterns are no longer just trends among innovative companies; they are fundamental elements required to effectively navigate the new microservice landscape as part of a cloud-native architecture. This is where the Service Mesh project is gaining traction as a viable solution to tackle these challenges and provide the necessary features.
Previously, I discussed Istio as one of the options available:
Integrating Istio with BWCE Applications
This article highlights the integration of BWCE applications using Istio as a Service Mesh to facilitate communication.
However, Istio, developed by Google and IBM, is not the sole option for achieving these functionalities. Linkerd, part of the CNCF ecosystem, offers comparable features.
Installing Linkerd
To begin utilizing Linkerd, you must first install the software on both the Kubernetes server and the local host.
For the host installation, navigate to the releases page, select the version compatible with your operating system, and install it.
I am using a Windows-based system for my demonstration, so I will employ Chocolatey for the client installation. After the installation, you can verify the CLI version by executing the following command:
linkerd version
The output should resemble the following:
PS C:WINDOWSsystem32> linkerd.exe version Client version: stable-2.8.1 Server version: unavailable
Next, we proceed to install Linkerd on the Kubernetes server using this command:
linkerd install | kubectl apply -f -
You should see an output similar to this:
PS C:WINDOWSsystem32> linkerd install | kubectl apply -f - namespace/linkerd created clusterrole.rbac.authorization.k8s.io/linkerd-linkerd-identity created ... deployment.apps/linkerd-grafana created
To ensure that the installation was successful, execute:
linkerd check
If everything is functioning correctly, your output will look like this:
PS C:WINDOWSsystem32> linkerd check kubernetes-api ---------------------------------- ? can initialize the client ? can query the Kubernetes API ...
You can access the Linkerd dashboard with the following command:
linkerd dashboard
Deploying Applications
For this deployment, I will use the same applications previously utilized for Istio, which you can review in my earlier article. The code is available in my GitHub repository: https://github.com/alexandrev/bwce-linkerd-scenario.
To deploy the applications, ensure your Docker images are pushed to a Docker registry. I will use Amazon ECR as the Docker repository.
Build and push the images with the following commands:
docker build -t provider:1.0 . docker tag provider:1.0 938784100097.dkr.ecr.eu-west-2.amazonaws.com/provider-linkerd:1.0 docker push 938784100097.dkr.ecr.eu-west-2.amazonaws.com/provider-linkerd:1.0
docker build -t consumer:1.0 . docker tag consumer:1.0 938784100097.dkr.ecr.eu-west-2.amazonaws.com/consumer-linkerd:1.0 docker push 938784100097.dkr.ecr.eu-west-2.amazonaws.com/consumer-linkerd:1.0
Now, deploy the images to the Kubernetes cluster:
kubectl apply -f ./provider.yaml kubectl apply -f ./consumer.yaml
You can then observe the applications in the Linkerd Dashboard under the default namespace:
To access the consumer endpoint, use:
kubectl port-forward pod/consumer-v1-6cd49d6487-jjm4q 6000:6000
Accessing the endpoint should yield a response from the provider.
The dashboard will display the provider's statistics:
Linkerd also offers a Grafana dashboard link for additional metrics, accessible via the dashboard interface.
Upon entering Grafana, the dashboard will present metrics like those shown below:
Conclusion
Through this guide, we've demonstrated how effortlessly Linkerd can be deployed within a Kubernetes cluster and how applications can seamlessly integrate and interact within this framework. Future articles will explore more advanced features that will assist in addressing the new challenges associated with microservices architecture.