In this tutorial, we will walk you through the step by step process to set up Linkerd as a service mesh for your Kubernetes cluster.
Linkerd is a light-weight service mesh for Kubernetes. It adds observability, reliability, and security to Kubernetes applications without code changes. For example, Linkerd can monitor and report per-service success rates and latencies, can automatically retry failed requests, and can encrypt and validate connections between services, all without requiring any modification of the application itself.
Linkerd is fully open source, licensed under Apache v2, and is a Cloud Native Computing Foundation incubating project. It is developed in the open in the Linkerd GitHub organization.
Linkerd has three basic components: a UI, a data plane, and a control plane. You run Linkerd by:
Once a service is running with Linkerd, you can use Linkerd’s UI to inspect and manipulate it.
This tutorial deploys Linkerd on a Platform9 Managed Kubernetes Free Tier cluster, however you can use it to deploy Linkerd on any Kubernetes cluster of your choice.
kubectl version --short
In order to install Linkerd as a Kubernetes Service Mesh, you need to download the Linkerd CLI. This CLI interacts with Linkerd, including installing the control plane onto your Kubernetes cluster.
Here’s the command to download the Linkerd CLI manually
xxxxxxxxxx
curl -sL https://run.linkerd.io/install | sh
You can also download a CLI directly from the Linkerd releases page if you want to install a specific version.
Add the Linkerd to your path and also consider adding it to your .bashrc file.
xxxxxxxxxx
export PATH=$PATH:$HOME/.linkerd2/bin
If you are using Homebrew, the command to install it is as follows:
xxxxxxxxxx
brew install linkerd
Once installed, you can verify the version of linkerd by running the command:
xxxxxxxxxx
linkerd version
To ensure that Linkerd’s CLI has been successfully installed and all the pre-requisites like namespace Linkerd not being present etc., run the following command:
xxxxxxxxxx
linkerd check --pre
All the checks in the above command should complete successfully, before proceeding.
xxxxxxxxxx
linkerd install | kubectl apply -f -
you can change configuration options like choosing a custom namespace for Linkerd Control plane by running the command:
xxxxxxxxxx
linkerd install -l | kubectl apply -f -
For eg.
xxxxxxxxxx
linkerd install -l linkerdtest | kubectl apply -f -
To explore all the available options while installing, run the command –
xxxxxxxxxx
linkerd install --help
Once the installation is complete, you can run the following command to verify if all the Linkerd components are running successfully.
xxxxxxxxxx
linkerd check
You can explore the Linkerd Dashboard by running the following command:
xxxxxxxxxx
linkerd dashboard &
If you are running this command from a Linux machine and would like the dashboard to listen on a specific interface instead of localhost by default, run the following command:
xxxxxxxxxx
linkerd dashboard --address &
This command sets up a port forward from your local system to the linkerd-web pod.
Here’s the simple command to install the Linkerd’s Control plane with all the default configuration.
NOTE: If you cannot access browser from the machine you are running the above linkerd command, you can make Linkerd dashboard listen on a specific interface IP instead of localhost by default, you’ll have to edit the enforced-host container argument and set it to an empty string. Detailed instructions are here under Tweaking Host Requirement Section.
Install the emojivoto application in the corresponding namespace by running the command –
xxxxxxxxxx
curl -sL https://run.linkerd.io/emojivoto.yml \
| kubectl apply -f -
You can take a look at this application by using a port forward for the web-svc service associated with the emojivoto application by running the command:
xxxxxxxxxx
kubectl -n emojivoto port-forward svc/web-svc 8080:80
Then, access the application using – http://localhost:8080/
NOTE: If you cannot access browser from the machine you are running the above kubectl command, you can make use the –address switch so you can reach it from your local machine and access it via a browser. The complete command is:
xxxxxxxxxx
kubectl -n emojivoto port-forward svc/web-svc 8080:80 --address
You might notice that that some parts of emojivoto app are broken. this is intentional and you can debug it further by checking out this link.
You can inject Linkerd into the newly deployed Demo application by running the command –
xxxxxxxxxx
kubectl get -n emojivoto deploy -o yaml \
| linkerd inject - \
| kubectl apply -f -
The first part of the command gets all the manifests from the emojivoto namespace; second part injects it with linkerd related metadata and then reapplies the configuration.
There will be no downtime associated with this operation as it would be a rolling deploy.
You can check if the above operation was successful by running the following command:
xxxxxxxxxx
linkerd -n emojivoto check --proxy
Demo app has an included load generator so you can observe the live metrics associated with the traffic flowing:
xxxxxxxxxx
linkerd -n emojivoto stat deploy
There’s a Grafana instance that comes prebuilt that shows metrics collected by Prometheus such as latency, request volume and success rate.