Deploying a Microservices Application with Istio as a Service Mesh on Rancher Kubernetes
Introduction
In modern cloud-native applications, microservices architecture is widely adopted due to its scalability and maintainability. However, managing the communication between microservices can be challenging. Istio, a popular service mesh, helps by providing traffic management, security, and observability. In this blog, we will explore how to deploy a microservices-based application with Istio on Rancher Kubernetes.
Prerequisites
To follow this guide, you need:
A Rancher-managed Kubernetes cluster
Kubectl and Istioctl installed
A containerized microservices application
Helm installed for managing Istio
Step 1: Install Istio on Rancher Kubernetes
Before deploying your application, you need to set up Istio.
1.1 Download and Install Istio
curl -L https://istio.io/downloadIstio | sh -
cd istio-1.x.x
export PATH=$PWD/bin:$PATH
1.2 Install Istio with Helm
helm install istio-base manifests/charts/base -n istio-system --create-namespace
helm install istiod manifests/charts/istio-control/istio-discovery -n istio-system
Step 2: Enable Istio Sidecar Injection
Istio uses a sidecar proxy to manage service-to-service communication.
kubectl label namespace default istio-injection=enabled
Step 3: Deploy the Microservices Application
3.1 Define Kubernetes Deployment and Service
Create deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-microservice
labels:
app: my-microservice
spec:
replicas: 3
selector:
matchLabels:
app: my-microservice
template:
metadata:
labels:
app: my-microservice
spec:
containers:
- name: my-microservice
image: my-microservice:latest
ports:
- containerPort: 8080
Create service.yaml
:
apiVersion: v1
kind: Service
metadata:
name: my-microservice
spec:
selector:
app: my-microservice
ports:
- protocol: TCP
port: 80
targetPort: 8080
Apply the configurations:
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
Step 4: Deploy Istio Gateway and Virtual Service
4.1 Define Gateway
Create gateway.yaml
:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: my-microservice-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "my-microservice.example.com"
4.2 Define Virtual Service
Create virtualservice.yaml
:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-microservice
spec:
hosts:
- "my-microservice.example.com"
gateways:
- my-microservice-gateway
http:
- match:
- uri:
prefix: "/"
route:
- destination:
host: my-microservice
port:
number: 80
Apply the configurations:
kubectl apply -f gateway.yaml
kubectl apply -f virtualservice.yaml
Step 5: Verify Deployment
Check the services and Istio components:
kubectl get pods -n istio-system
kubectl get svc -n istio-system
kubectl get virtualservices
kubectl get gateways
Test the application:
curl -H "Host: my-microservice.example.com" http://<EXTERNAL_IP>
Conclusion
By deploying Istio as a service mesh in Rancher Kubernetes, you gain better control over microservices networking, security, and observability. With this setup, you can easily manage traffic, apply security policies, and monitor service interactions efficiently.