Istio with k8s
Updated: 03 September 2023
Prerequisites
- Trial IBM Cloud Account
- Kubrenetes Cluster
- Kubernetes 1.9.x or later
- IBM Cloud CLI with Kubernetes
Setting Up The Environment
Access Your Cluster
List your available clusters and then download the config and set an environment variable to point to it with
Then you can check the workers in your cluster and get information with
You can get your nodes, services, deployments, and pods with the following
Clone the Lab Repo
You can clone the lab repo from https://github.com/IBM/istio101
and then navigate to the workshop
directory
Install Istio on IBM Cloud Kubernetes Service
Download Istio from here and extract to your root directory
Then add the istioctl.exe
file to your PATH
variable
Thereafter navigate to the istio-demo.yaml
file in the istio folder that you extracted and do the following
If you run into the following error
Make sure that your $env:KUBECTL
variable is set, if not get your cluster config and set it again
Once that is done, check that the istio services are running on the cluster with
Download the App and Create the Database
Get the App
Clone the app from the GitHub repo
Create the Database
Next we can create a Redis Database with the following master and slave deployments and services from the Yaml files in the Guestbook project
Install the Guestbook App with Manual Sidecar Injection
Sidecars are utility containers that support the main container, we can inject the Istio sidecar in two ways
- Manually with the Istio CLI
- Automatically with the Istio Initializer
With Linux you can do this
But, if you’re on Windows and you need to redirect your output, use this instead
Then create the Guestbook Service
Adding the Tone Analyzer
Create a Tone Analyzer Service and get the credentials, then add these to the analyzer-deployment.yaml
file
Then do the following
Service Telemetry and Tracing
Challenges with Microservices
One of the difficulties when using microservices is identifying issues and process bottlenecks as well as debugging
Istio comes with tracing built in for this exact purpose
Configure Istio for Telemetry Data
In the v2 directory, do the following
Generate a Load on the Application
Then we can then generate a small load on our application from the worker’s IP and Port
Or for a lite plan
We can get our telemetry data at intervals with the following in Bash
View Data
Jaeger
We can find the external port for our tracing service and visit it based on that
Grafana
We can establish port forwarding for Grafana and view the dashboard on localhost:3000
Prometheus
We can view the Prometheus dashboard at localhost:9090
Service Graph
Can view this at http://localhost:8088/dotviz
Expose the Service Mesh with Ingress
Ingress Controller
Istio components are by default not exposed outside the cluster, an Ingress is a collection of rules that allow connections to reach a cluster
Navigate to the istio101\workshop\plans
directory
Using a Lite Account
Configure the Guestbook App with Ingress
Then check the node port and IP of the Ingress
In my case, I have the endpoint 159.122.179.103:31380
which is bound to port 80
Using a Paid Account
Set up a Controller to work with IBM Cloud Kubernetes Service
This will only work with a paid cluster
Get your Ingress subdomain
Then add this subdomain to the frontdoor.yaml
file, and create and list the details for your Ingress
Traffic Management
Traffic Management Rules
The core component for traffic management in istio is Pilot. This manages and configures all the Envoy proxy instances in a service mesh
Pilot translates high level rules into low level configurations by means of the following three resources
- Virtual Services - Defines a set of routing rules to apply when a host is addressed
- Destination Rules - Defines policies that apply to traffic intended for a service after routing has occurred, specifications for load balancing, connection pool size, outlier detection, etc
- Service Entries - Enables services to access a service not necessarily managed by Istio
A/B Testing
Previously we had created two versions of the Guestbook app, v1 and v2. If we do not have any rules, istio will distribute requests evenly between the instances
To prevent Istio from using the default routing method we can do the following to route all traffic to v1
Incrementally roll our changes
We can incrementally roll our changes by changing the weighting of our different versions
Circuit Breakers and Destination Rules
Istio lets us configure settings for destination rules as well as implementing circuit breakers for Envoys
Securing Services
Mutual Auth with Transport Layer Security
Istio can enable secure communication between app services without the need for application code changes. We can delegate service control to Istio instead of implementing it on each service
Citadel is the Istio component that provides sidecar proxies with an identity certificate . Envoys then use these certificates to encrypt and authenticate communication along channels between these services
When a microservice connects to another microservice communication between them is redirected through the Envoys
Setting up a Certificate Authority
First check that Citadel is running
Do the following with bash
Then set the environment variable, and paste the following
You can then confirm the policy is set with
Next we can enable mTLS from a guestbook with a Destination Rule
Verify Authenticated Connection
We can ssh into a pod by getting the pod name and opening the terminal
Then we should be able to view the certificate pem
files as follows
Enforcing Isolation
Service Isolation with Adapters
Back-end systems typically integrate with services in a way that creates a hard coupling
Istio uses Mixer to provide a generic intermediate layer between app code and infrastructure back-ends
Mixer makes use of adapters to interface between code and back-ends
- Denier
- Prometheus
- Memquota
- Stackdriver
Using the Denier Adapter
Block access to the Guestbook service with
The rule we have created is as follows
We can verify that the access is denied by navigating to our Ingress IP, next we can remove the rule with