In this tutorial, you will learn step by step instructions to set up Istio as a service mesh for your Kubernetes cluster.
One of the challenges with a highly dynamic microservices architecture is creating and maintaining connections. As pods are updated, added, and removed, you need a mechanism to identify each pod and enable communication between them and other pods in the cluster. A service mesh is one way of managing the communications within your cluster. Network proxies are attached to each application container using the Sidecar pattern. Together these proxies operate and monitor communication within the Kubernetes cluster, and this is the service mesh. The service mesh manages security, works to optimize network performance within the cluster, and reports on the state of networking within the Kubernetes cluster.
The first step is to log into the node and download Istio. We do that with the following command.
xxxxxxxxxxcurl -L https://istio.io/downloadIstio | sh -The command above will download the latest version of Istio to the current directory. At the time of writing, the newest version was 1.8.1. Navigate into the newly-created directory.
xxxxxxxxxxcd istio-1.8.1You’ll see the following content in this directory:
samples/ directory.istioctl client binary in the bin/ directory. istioctl is a helpful command line tool that enables you to install istio on your Kubernetes cluster node along with a set of other operations.We need to add the bin directory to our path, so that we can invoke the istioctl CLI tool from anywhere on this node.
xxxxxxxxxx$ export PATH=$PWD/bin:$PATHWhen you install Istio, you are able to choose from several configuration profiles. We will use the demo profile for this guide because it showcases the abilities of Istio with moderate resource usage. Other profiles are more appropriate for production deployments and custom configurations.
We will use istioctl to specify the demo profile and install the istio service.
xxxxxxxxxxistioctl install --set profile=demo -yThe installation may take a few minutes to complete, but ultimately you’ll see output similar to that shown below.
xxxxxxxxxx✔ Istio core installed ✔ Istiod installed ✔ Egress gateways installed ✔ Ingress gateways installed ✔ Installation completeThe final step is to add a namespace label to enable Istio to automatically inject Envoy sidecar proxies when you deploy your application pods later.
xxxxxxxxxxkubectl label namespace default istio-injection=enabledIstio is now deployed and configured on your Kubernetes cluster node. We are now ready to deploy a sample application and see Istio in action.
Istio comes packaged with several sample applications in the sample directory under the installation folder. In this guide we will deploy the bookinfo application using kubectl. Run the following command from the root directory for the Istio installation.
xxxxxxxxxxkubectl apply -f sample/bookinfo/platform/kube/bookinfo.yamlThe YAML configuration file creates several services for us. You can see a summary of all the installed services by running the following.
xxxxxxxxxxkubectl get servicesxxxxxxxxxxNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE details ClusterIP 10.21.2.22 < none > 9080/TCP 39s kubernetes ClusterIP 10.21.0.1 < none > 443/TCP 48m productpage ClusterIP 10.21.0.74 < none > 9080/TCP 38s ratings ClusterIP 10.21.1.6 < none > 9080/TCP 39s reviews ClusterIP 10.21.3.241 < none > 9080/TCP 39sWe also need to ensure that all of the pods are ready to go, as this may take a little more time. We can see this on our node directly by executing kubectl get pods, or we can view their status on the Platform9 dashboard.
xxxxxxxxxxkubectl get podsWe need two (2) of each pod to have a status of running.
xxxxxxxxxxNAME READY STATUS RESTARTS AGE details-v1-558b8b4b76-ck1g5 2/2 Running 0 10m productpage-v1-6987489c74-b64sn 2/2 Running 0 10m ratings-v1-7dc98c7588-qb4ng 2/2 Running 0 10m reviews-v17f99cc4496-7cd47 2/2 Running 0 10m reviews-v2-7d79d5bd5d-5gz7j 2/2 Running 0 10m reviews-v3-7dbcdcbc56-k7wh1 2/2 Running 0 10mThis configuration creates two resources in the cluster:
Istio includes an analysis tool that validates your istio installation. Now with everything we’ve completed deploying our application, we can use this tool to validate our namespace.
xxxxxxxxxxistioctl analyzexxxxxxxxxx✔ No validation issues found when analyzing namespace: defaultFor the next step, we need to determine if the environment has an internal or external load balancer. Execute the following command.
xxxxxxxxxxkubectl get svc instio-ingressgateway -n istio-systemIn the output, look for the EXTERNAL-IP. If the results show an IP Address or a Host Name, then you have an external load balancer. If the results show either or , you don’t have access to an external load balancer. Export the following Environment Variables (EVs) based on whether you have an external load balancer or not.
xxxxxxxxxxexport INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') $ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}') $ export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].port}')xxxxxxxxxxexport INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}') $ export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}') $ export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')With those EVs set, you can now set your Gateway URL.
xxxxxxxxxxexport GATEWAYURL=$INGRESS HOST:$INGRESS_PORTExecute the following command to get the external address for the BookInfo application, and paste it into your web browser to access the application.
xxxxxxxxxxecho “http://$GATEWAY_URL/productpage”Monitoring Kubernetes and Istio
xxxxxxxxxxkubectl apply -f samples/addonsAnd now, let's deploy Kiali to view the dashboard.
xxxxxxxxxxkubectl rollout status deployment/kiali -n istio-systemWe can open the dashboard using:
xxxxxxxxxxistioctl dashboard kialiFor more information on Istio as a Kubernetes service mesh, the latest documentation is available here If you’re looking for more information about service meshes, including tips on selecting and implementing a service mesh, the following articles have a great deal of helpful information. Comparing Kubernetes service mesh options and how to migrate between them
In this blog, we walked through a tutorial on setting up Istio as a Kubernetes service mesh using a PMK account. We hope you found this blog informative and engaging.