1

Istio in Kubernetes - Getting Started

 3 years ago
source link: https://www.programmingwithwolfgang.com/istio-getting-started/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Istio in Kubernetes - Getting Started

1 day ago2021-08-16T00:00:00+02:00 by Wolfgang Ofner
10 min

My last post introduced the concept of a service mesh and how it can help to manage your Kubernetes cluster, especially with hundreds or thousands of pods running. The post was only theoretical and was probably a bit abstract if you have never worked with a service mesh.

Therefore, I want to show you how to install Istio and a sample application on your Kubernetes cluster in this post.

This post is part of “Microservice Series - From Zero to Hero”.

Installing Istio in Kubernetes

This demo assumes that you already have a Kubernetes cluster set up. If you don’t see Azure Kubernetes Service - Getting Started to set up a new cluster and also configure the connection to Kubernetes. Usually, I work with Windows but for this demo, I will use the Windows Subsystem for Linux. You can use all commands on Linux or Max as well.

To get started, download the newest version of Istio.

curl -L https://istio.io/downloadIstio | sh -

Download the newest Version of Istio

Alternatively, go to Github and download the desired version.

After the download is finished, navigate into the downloaded Istio folder and set the path to the /bin folder as the Path variable.

cd istio-1.10.3
export PATH=$PWD/bin:$PATH

Set the Istio Path

Next, install Istio with the demo profile in your Kubernetes cluster. Istio comes with several profiles which have different configurations for the core components. The demo profile installs all components. You can find more information about the profiles in the Istio docs.

istioctl install --set profile=demo -y

Install Istio in Kubernetes

The installation should only take a couple of seconds.

Install an Istio Demo Application

Istio offers a nice demo application which I will use in this demo. Before you install it, I would recommend creating a new namespace in your K8s cluster. Additionally, set the istio-injection=enabled label on the namespace. This label configures the automatic injection of the Envoy sidecar.

kubectl create namespace istio-demo
kubectl label namespace istio-demo istio-injection=enabled

Create and tag the Namespace

Next, install the sample app in the previously created namespace.

kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml -n istio-demo

Install the Sample Application

After the sample application is installed, make sure that all services are up and running.

kubectl get services -n istio-demo

Check the installed Services

Also, check that all pods are started and running correctly.

kubectl get pods -n istio-demo

Check the installed Pods

The demo application is only accessible through the internal network. To make it accessible from the outside, install the Istio in the same namespace.

kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml -n istio-demo

Install the Gateway

The gateway acts as a load balancer and only provides an external URL. Use the following command to get the application’s URL and its ports.

kubectl get svc istio-ingressgateway -n istio-system

Get the IP Adresse of the Sample Application

Alternatively, use the following commands to read the URL and port and combine them in the GATEWAY_URL variable.

export 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}')
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT

Test the Sample Application

Enter URL:Port/productpage in your browser and you should see the sample application.

Test the Sample Application

Install Istio Addons

Istio comes with a wide range of additional software which can be easily installed with the following command.

kubectl apply -f samples/addons

Install Istio Addons

This installs every available addon. If you only want to install certain products, use their specific YAML files. For example, install only Prometheus with the following command.

kubectl apply -f samples/addons/prometheus.yaml

The above code installed many useful tools like Grafana, Jaeger, or Zipkin. I will talk more about these tools in my next post. For now, let’s take a look at Kiali which is a pretty cool tool to visualize the flow and useful information of requests in distributed applications. Kiali is already installed. All you have to do is to activate the port forwarding with the following command.

istioctl dashboard kiali

Open your browser, enter localhost:20001 and you should see the Kiali dashboard. On the left side select Graph, then select the istio-demo namespace from the drop-down and you should see the services of the demo application. Execute the following command to produce 100 requests which then will be visualized in the graph.

for i in $(seq 1 100); do curl -s -o /dev/null "http://$GATEWAY_URL/productpage"; done

Play a bit around with the settings. You can, for example, enable the traffic animation and the response time of the requests. The graph also shows that most of the traffic is routed from the productpage to the details microservice.

Traffic Flow with Kiali

Analyzing Istio Errors

Istio is very robust but sometimes things go wrong. You can analyze a namespace with the following command.

istioctl analyze -n istio-demo

If you followed this demo and don’t add a namespace (-n istio-demo), the analysis process will run in your current namespace (usually the default namespace) and will return an error that Istio is not enabled.

Check for Errors

Conclusion

Istio is an easy to install service mesh that comes with many useful applications like Grafana, Prometheus, and Jaeger. This demo used the Istio demo application and showed how to visualize your microservice dependencies and the request flow using Kiali.

In my next post, I will show you more features of Istio like fault injection, request routing and traffic shifting between microservices.

This post is part of “Microservice Series - From Zero to Hero”.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK