
Istio is a service mesh implementation that enables observability of your services to monitor how services communicate with each other through a visual dashboard. In addition, Istio also allows you to simplify the canary deployment process so that you can safely deploy a new version of your application to a small number of users and monitor how they interact with it. It also supports the mutual transport layer security (mutual TLS) for requests sent amongst your services, which adds an extra layer of security defense system for your cluster applications.
Istio consists of two main components, the data and control planes as below:
This article explains how to install and use Istio on a Vultr Kubernetes Engine (VKE) Cluster. You are to apply Istio to your applications to achieve observability, traffic management, and security improvement in your cluster.
Before you begin, you should:
On the management machine:
Download and install istioctl that lets you install Istio components to your cluster
Switch to the downloaded Istio directory. Replace 1.18.2 with your actual Istio version number
Add the istioctl command to your environment variables to allow usage from any directory.
Verify that you can access the istioctl tool
Output:
To connect to your VKE cluster, verify that you installed kubectl, then export the KUBECONFIG environment variable with your VKE cluster YAML file as described below.
Export the KUBECONFIG environment variable with the path to your VKE configuration file
View the cluster notes to verify that kubectl connects to the VKE cluster
You should see a similar result as below:
Istio supports built-in configuration profiles and customized profiles to match the vendor-specific platform. Use the default profile to deploy Istio in production deployment. For this article, use the demo profile to install Istio as described below.
Run the following command to install Istio using the demo profile
You should see a similar output as below:
The above components install in the istio-system namespace. With the demo profile, Istio installs istiod, istio-egressgateway, and istio-ingressgateway components as below:
istiod: The Istio control plane component responsible for managing proxies and traffic routingistio-ingressgateway: Allows you to define entry points for your servicesistio-egressgateway: Allows you to define exit points for your servicesRun the following command to list the Istio pods
Output:
As displayed in the output, verify that all Istio components are ready and running.
In this section, configure Istio to apply service mesh for the demo application deployed on your VKE cluster.
Istio injects Envoy proxies into the application pods to enforce constant communication with each other. As a result, the Istio control plane can apply traffic management, observability, and security enhancement through the Envoy proxies.
To allow Istio mark pods it should inject with the Envoy proxy, label the namespace that the pods belong to with the is-injection=enabled option. For example. run the following command to mark the default namespace with is-injection=enabled
Output:
The is-injection=enabled label marks all pods in the default namespace. Deploy a sample application to test the Envoy proxy functionality
In this section, deploy a sample bookinfo application that has the following services:
product page: Retrieves book information from the details and reviews services.reviews: Contains the book review. It has three versions: v1, v2, and v3.ratings: Stores the book ranking informationdetails: Stores the book informationWithin the Istio package directory you downloaded on installation, sample deployment scripts for the bookinfo app are available within the sample sub-directory
Switch to the Istio data directory
Deploy the bookinfo application to the default namespace.
Output:
After a few minutes, verify the status of the pods
Your output should look like the one below:
As displayed in the above output, each pod has two running containers, the application container, and the envoy proxy container
To view the containers inside a pod, for example, pod details-v1-7c7dbcb4b5-tvkml, run the following command:
Output:
In the above output:
details is the container name of the application containeristio-proxy is the Envoy proxy name injected by Istio into the podYour sample application requires customers to retrieve book information using the productpage service. To enable access to the bookinfo application, you need to:
productpage serviceWithin the Istio data directory, use a text editor such as Nano to create a new file named istio-gateway.yaml
Add the following contents to the file
Save and close the file.
In the above configuration, you set the Istio gateway named bookinfo-gateway and chose the selector type as ingressgateway. This means incoming traffic forwards to the Istio service mesh. The gateway on port 80 accepts HTTP traffic and sets the gateway to accept any hostname.
Apply the configuration to create the Istio gateway
Output:
View the EXTERNAL-IP of the Istio gateway
Your output should appear like the one below:
Using curl, make an HTTP request to the gateway
The request returns an empty result because you need to implement a mechanism to forward the request to the target application.
Create a new file named product-page-virtual-service.yml
Add the following configurations to the file
Save and close the file.
The above configuration defines an Istio VirtualService to forward requests with the URL $GATEWAY-URL/productpage to the productpage service on port 9080.
Run the following command to create the VirtualService for the above configuration
Your output should appear like the one below:
Make an HTTP request to the Istio gateway again
You should view the content of your product page service as below:
Enable observability, traffic management, and security enhancement for your application using Istio as described in the following sections.
To enable observability in the application, install Kiali to visualize how services communicate with each other. Additionally, implement addon services like Prometheus or Jaeger to collect service metrics as described in the steps below.
The Istio data directory contains all necessary addons, install them to your cluster using the following command
Wait for a few minutes for the installation of all required addons to complete. When successful, your output should look like the one below:
Start the Kiali dashboard in the background to view how services in the bookinfo app communicate
The above command forwards your Kiali cluster port to your localhost machine IP address. When successful, your output should appear like the one below:
Later, to stop the Kiali dashboard background process, view the job ID
Stop the background process by job ID. For example, job id 1.
By default, the istioctl dashboard kiali port forwarding command only accepts connections from the localhost hostname address 127.0.0.1. To access the dashboard using your public management Server IP, set up a new configuration file to enable Nginx as a reverse proxy using the command below
Add the following configurations to the file
Save and close the file
The above configuration securely forwards all requests to the Nginx listening port 8080 to the Kiali dashboard localhost port 20001 for further processing.
Enable the listening port 8080 through the firewall
Using a web browser such as Chrome, access the Kiali dashboard
The main Kiali dashboard interface should display in your browser window.
In your terminal session, send sample requests to the bookinfo application to view how the services interact with each other. Replace 192.0.2.100 with your actual cluster external address
On the main navigation menu, click Graph
On the top bar, click the Select Namespaces button, and check Select all to read all cluster namespaces
Verify that the graph displays how services send requests to each other
As displayed in the graph, requests distribute evenly for the reviewers service version v1, v2, v3, this is the built-in support for traffic management that Istio offers. By default, Istio applies the least request load balancing algorithm to distribute requests to the pods.
In your terminal session, press Ctrl + C to stop sending sample requests
To apply customized traffic management for your services, create a new virtual service and destination rule to distribute the traffic to different versions of the reviewer service as described below.
In your terminal session, create a new file named custom-traffic-management.yaml
Add the following contents to the file
Save and close the file.
In the above configuration, the DestinationRule resource definition instructs Istio to label the reviews service versions into different subsets as v1, v2, and v3. The VirtualService resource definition instructs Istio to distribute different traffic weights to different versions of the reviews service by their subsets label as below:
reviews service version 1reviews service version 2reviews service version 3Apply the resource to your cluster
Again, send some requests to the bookinfo application
In your browser session, access the Kiali dashboard, find, and click the refresh button in the top right corner to view the traffic graph again.
As displayed in the updated graph, the ratio of requests for each reviews service version is different. The reviews service version 2 should have the most significant number of traffic.
To enable services inside the Kubernetes cluster to securely communicate with each other and prevent MITM (Man in the Middle) type of attacks, enable TLS authentication on external traffic requests. However, using TLS for every service in your application is time consuming depending on the number of running services. With this difficulty, Istio supports TLS using mutual TLS that allows both the client and server to verify the identities of each other.
Below are the supported Istio mutual TLS authentication modes:
To better note the difference between the permissive and strict mode, send an HTTP request to the productpage service without using the gateway endpoint.
Run the following command to list the services in your Kubernetes cluster
Your output should appear like the one below:
As displayed in the output, the productpage service uses the ClusterIP type with no EXTERNAL-IP value for you to access it.
To set the service EXTERNAL-IP value, change the ClusterIP type to LoadBalancer using the following command
The above command opens the service YAML configuration in the vim text editor. Scroll the Selector section, find the type: ClusterIP entry, press I on your keyboard to edit the file, and change the value type: LoadBalancer
Press Esc, enter :, and add W + Q to save the file, and close the editor.
Wait for a few minutes for Kubernetes to apply changes, and check the cluster services again
You should see a similar output as below:
Verify that the productpage service now has your loadbalancer's external IP value.
Run the following command to make a HTTP request to the productpage service using its EXTERNAL-IP address
The productpage service response should look like the one below:
Because Istio applies the permissive mutual TLS mode by default, a client can send HTTP requests to the service.
To change the mutual TLS mode to strict mode, create a new file named strict-mode-tls.yaml
Add the following contents to the file
Save and close the file.
The above configuration instructs Istio to apply the strict mode to the PeerAuthentication resource within the istio-system namespace.
Apply the change to your cluster
Wait for a few seconds for Istio to apply the change. Then, try to make an HTTP request to the productpage again
This time, you should receive an error message from the productpage service as below:
The above error displays because Istio now applies a strict mode for the mutual TLS authentication. If the client does not send an HTTPS request to the service, Istio does not allow the client to interact with the service.
In this article, you used Istio to apply observability, traffic management, and security enhancement for your application. To further implement Istio in your cluster, visit How to Use Istio for Ingress Gateway without TLS Termination on VKE to send encrypted SSL requests directly to the NGINX server.
For more information about Istio, visit the following resources:
0 Comments
Be the first to comment and share your perspective with the community.