0
0
Kubernetesdevops~5 mins

Observability with service mesh in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run many small services together, it can be hard to see how they talk and work. A service mesh helps by adding tools that watch and report on these connections automatically.
When you want to see detailed traffic flow between your microservices without changing their code
When you need to find slow or failing services quickly in a complex app
When you want automatic collection of logs, metrics, and traces from your services
When you want to control and secure service communication with visibility
When you want to add observability features without adding extra work to your developers
Config File - istio-demo.yaml
istio-demo.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: my-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-service
spec:
  hosts:
  - "my-service"
  gateways:
  - my-gateway
  http:
  - route:
    - destination:
        host: my-service
        port:
          number: 80

This file sets up an Istio Gateway to allow external traffic and a VirtualService to route that traffic to your service named my-service. The Gateway listens on port 80 for HTTP requests. The VirtualService tells Istio how to send requests to the service inside the mesh.

Commands
This command creates the Gateway and VirtualService in your Kubernetes cluster to enable traffic routing and observability features.
Terminal
kubectl apply -f istio-demo.yaml
Expected OutputExpected
gateway.networking.istio.io/my-gateway created virtualservice.networking.istio.io/my-service created
Check that the Istio components, including the observability tools, are running properly in the istio-system namespace.
Terminal
kubectl get pods -n istio-system
Expected OutputExpected
NAME READY STATUS RESTARTS AGE istio-ingressgateway-5d8f7f6f7b-abcde 1/1 Running 0 10m istiod-7f9d8f7f7b-xyz12 1/1 Running 0 10m
Find the external IP or port to access your services through the Istio ingress gateway.
Terminal
kubectl get svc istio-ingressgateway -n istio-system
Expected OutputExpected
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE istio-ingressgateway LoadBalancer 10.96.123.45 34.68.123.45 80:31380/TCP,443:31390/TCP 10m
Open the Kiali dashboard, a visual tool that shows service mesh traffic and observability data in your browser.
Terminal
istioctl dashboard kiali
Expected OutputExpected
Starting Kiali dashboard proxy on http://localhost:20001 Press Ctrl+C to exit
Key Concept

If you remember nothing else from this pattern, remember: a service mesh adds automatic observability by managing and reporting on service communication without changing your app code.

Common Mistakes
Not installing the service mesh control plane before applying Gateway and VirtualService resources
The resources depend on the control plane to work; without it, they won't be recognized or function.
Install Istio or your chosen service mesh first using its official installation commands before applying configuration files.
Trying to access services without exposing the ingress gateway service externally
Without an external IP or port, you cannot reach your services from outside the cluster.
Ensure the ingress gateway service is of type LoadBalancer or NodePort and note its external IP or port.
Ignoring the namespace when checking pods or services
Istio components run in the istio-system namespace; commands without -n istio-system will not find them.
Always specify the correct namespace with -n istio-system when managing Istio resources.
Summary
Apply Gateway and VirtualService YAML files to configure traffic routing and observability.
Verify Istio system pods are running to ensure observability tools are active.
Check the ingress gateway service to find how to access your mesh-enabled services.
Use the Istio Kiali dashboard to visually monitor service communication and health.