On these days, microservices are improving our productivity, scalability and the disponibility of our apps and saving time (Woow!), to support the security and access control we can use the service mesh to do that so let’s make an example using: dotnetcore, kubernetes and kuma 🙂
Our ingredients:
1 – Kubernetes;
2 – Kuma Mesh;
3 – Dotnetcore
In this example we gonna build two applications to simulate a communication (Requesting an GUID) inside our Service Mesh:
SERVICE CLIENT ——-> REQUEST ——-> SERVICE SERVER
SERVICE SERVER ——-> RESPOND ——-> SERVICE CLIENT
OBS: It’s really simple but when we’re inside a Service Mesh we don’t have an IP fixed so we have to request to the Service Data Plan (Kuma) the address of the service that we need to access our GUID.
Installing the application Server
kubectl apply -f https://bit.ly/3vjbfqb
Installing the application Client
kubectl apply -f https://bit.ly/3veZLUH
OBS: To set our Service Mesh in our application we have to enable the SIDECAR (in this case Kuma) in the manifeste file.
To check if everything is ok, let’s list our new namespace created:
kubectl get all -n dotnetcore
So we can see that we have our two app running! bravo!
No let’s check if our mesh is running correctly and if we can see our apps.
We can use the Kuma-GUI just to read our information, so let’s go!
kubectl port-forward svc/kuma-control-plane -n kuma-system 5681:5681
Access the Kuma-GUI on the address: http://localhost:5681/gui/#/default/standard-dataplanes
Cool! we can see that our Mesh is running correctly and we can see the apps!
Now let’s check the address of the services because we don’t have public IP:
To find out the address that we need to use, we have to check the DP (data plane) of our apps!:
kubectl get dataplanes -n dotnetcore
We can see that we have two DPs because we have two apps running:
So let’s get the details of our application server:
kubectl describe dataplane webapiapp-6888d649fb-7h9ql -n dotnetcore
We can see that we have lot of information about our DP but now we just need the address that we gonna use to call this service so in our app client we have to make a request to this address to get our response!
In this case our app client is already coded and ready! but just to ilustrate in app client we just did a simple webrequest to our app server and read the response:
[HttpGet]
public string Get()
{
string sURL = "http://webapiapp-service_dotnetcore_svc_80.mesh/guid";
WebRequest wrGETURL = WebRequest.Create(sURL);
Stream objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
string sLine = "";
int i = 0;
StringBuilder strBd = new StringBuilder();
while (sLine != null)
{
i++;
sLine = objReader.ReadLine();
if (sLine != null)
strBd.AppendLine(String.Format("{0}:{1}", i, sLine));
}
return strBd.ToString();
}
Now let’s try our app client!
kubectl port-forward service/webapiclientapp-service -n dotnetcore 8081:80
No let’s access our app client available at: http://localhost:8081/guid
Voila! our app client is running and calling our app server and showing the response!
So we have our apps running inside our Service Mesh Kuma on Kubernetes! 🙂