Skip to content

Instantly share code, notes, and snippets.

@lucasponce
Last active March 2, 2020 19:16
Show Gist options
  • Save lucasponce/263c778e567148bae8585159ac5599c4 to your computer and use it in GitHub Desktop.
Save lucasponce/263c778e567148bae8585159ac5599c4 to your computer and use it in GitHub Desktop.
Sharing my setup: How I develop on Kiali

Hi,

Kiali maintainers typically work on a full stack basis contributing into back-end and front-end repos.

Here I'm going to share some notes about my laptop setup that hope it may help to new maintainers to jump into the project and prepare your first PR.

The way you setup your workstation could be quite personal, so I don't think there are two Kiali maintainers sharing the same :-).

Hardware & Operating System

Lenovo T580 (32 GB Ram)

Fedora release 31 (yes, I use Linux, and yes, I use IRC, in case you asked).

Languages an environment setup

Being familiar with basic operations using Git and Github is a must.

You should be able to fork and clone Kiali back-end and front-end repos.

Kiali back-end is based in Golang.

Specific dependencies and tooling are described in the README: https://github.com/kiali/kiali/blob/master/README.adoc#building

Kiali front-end is based in TypeScript.

Specific dependencies and tooling are described in the README: https://github.com/kiali/kiali-ui/blob/master/README.adoc#quick-start

IDEs

No IDE is necessary to develop in Kiali.

But we recommend to choose one, every Kiali maintainer has its favourite, in my case I use Goland for back-end and WebStorm for front-end.

My decision is due productivity, on my particular case I learnt a lot of shortcut keys and the debugging experience and integrated terminals in the IDE is good for me. Also I'm a fan of Scratches developer tool.

Note that this is not any kind of recommendation or debate about pros/cons.

Use whatever makes you feel productive and save time to focus just in the code :-).

The Cloud - Kubernetes - MiniKube - Istio

Kiali is a dashboard for Istio.

That means that we need a cloud platform to develop.

Kiali maintainers use several but the most common is minikube, so here I will describe my steps to install it.

First, you should install a kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/

The way I install a fresh minikube with Istio on top ready to develop is this:

#!/usr/bin/env bash
# Platform Setup
minikube config set vm-driver kvm2
minikube start --memory=16384 --cpus=4 --kubernetes-version=v1.14.2
minikube addons enable registry

export ISTIO_HOME=$HOME/Software/istio-1.4.3
export PATH=$PATH:$ISTIO_HOME/bin

istioctl manifest apply --set profile=demo --set values.tracing.enabled=true

echo "Waiting to istio-system pods - CTRL+C to continue"
kubectl get pods -n istio-system -w

cd $ISTIO_HOME
kubectl label namespace default istio-injection=enabled
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

kubectl get pods -n default -w

When the setup is done, you should see the pods of the default and istio-system namespaces like this:

$ kubectl get pods
NAME                             READY   STATUS    RESTARTS   AGE
details-v1-c5b5f496d-t6zn6       2/2     Running   0          2m6s
productpage-v1-c7765c886-s7ws9   2/2     Running   0          2m6s
ratings-v1-f745cf57b-9tbm8       2/2     Running   0          2m6s
reviews-v1-75b979578c-45759      2/2     Running   0          2m7s
reviews-v2-597bf96c8f-lbpth      2/2     Running   0          2m7s
reviews-v3-54c6c64795-hh868      2/2     Running   0          2m7s

$ kubectl get pods -n istio-system
NAME                                      READY   STATUS    RESTARTS   AGE
grafana-5f798469fd-8p64g                  1/1     Running   0          4m27s
istio-citadel-6d6cbfdddb-k62z9            1/1     Running   0          4m28s
istio-egressgateway-cc5d84bb7-v8nfm       1/1     Running   0          4m29s
istio-galley-f65ffd68d-vvsb9              1/1     Running   0          4m28s
istio-ingressgateway-5db78457f5-zf8gh     1/1     Running   0          4m29s
istio-pilot-677746c74c-pj48m              1/1     Running   0          4m28s
istio-policy-745ff9fd59-jg8pv             1/1     Running   2          4m28s
istio-sidecar-injector-75ff97b4d8-jvh92   1/1     Running   0          4m28s
istio-telemetry-7b84df9f9-b8qft           1/1     Running   2          4m28s
istio-tracing-cd67ddf8-6mxrl              1/1     Running   0          4m29s
kiali-7964898d8c-rrljq                    1/1     Running   0          4m28s
prometheus-586d4445c7-4dtp2               1/1     Running   0          4m28s

Note that kiali repo provides a hack folder with helper scripts to run all of this, but I think it's good to install it one time in a manual way to get familiar with all the setup for future troubleshooting.

At the end of this step, you will have a local kubernetes cluster with Istio and a demo app deployed.

The trick - Define proxies

Kiali is typically deployed within the cluster inside the istio-system namespace and via a Kiali operator.

We will talk about this later, but now we are developers and we want to code from our IDEs, make changes, tests in a quick and flexible way.

So accomplish this we define several proxies to the services that Kiali would need to start a process out of the cluster.

From a new terminal, start a proxy with kubernetes API:

  $ kubectl proxy --port 8080
  Starting to serve on 127.0.0.1:8080

From a new terminal, start a proxy with Istio's Prometheus server, I use this script, but you can always create your own version:

#!/usr/bin/env bash
# Prometheus Pod from minikube
P8S_POD=$(kubectl get pod -n istio-system -l app=prometheus -o=jsonpath={.items[*].metadata.name})
echo "Prometheus port-forward"
echo "kubectl port-forward -n istio-system $P8S_POD 19090:9090"
while true
do
    kubectl port-forward -n istio-system $P8S_POD 19090:9090
done

From a new terminal, create a proxy with Jaeger server, I also have a similar script to detect the pod and forward the port to my localhost:

#!/usr/bin/env bash
# Jaeger Pod
JAEGER_POD=$(kubectl get pod -n istio-system -l app=jaeger -o=jsonpath={.items[*].metadata.name})
echo "Jaeger port-forward"
echo "kubectl port-forward -n istio-system $P8S_POD 16686:16686"
kubectl port-forward -n istio-system $JAEGER_POD 16686:16686

With these 3 proxies, we have available on localhost 8080, 19090 and 16686 ports the three main services that Kiali uses to perform backend queries.

Not all features will be available, but at least will help to develop in most of the areas of the project.

Start a Kiali back-end process from your IDE

One of the reasons I like Goland is that I can start a Kiali process within the IDE with minimal steps.

Then debugging gets simplified and I can stop and inspect in any line just to learn why something is not working.

To do this I use the "Go Build" profile in the Run/Debug Configurations.

I'm sure this can be done in other IDEs or just from a terminal with minor changes.

You need to add a couple of env variables to the Kiali process.

Environment (pointing to the main Kubernetes proxy):

KUBERNETES_SERVICE_HOST=localhost;KUBERNETES_SERVICE_PORT=8080

Program Arguments (adding a custom Kiali config yaml):

-config /home/lponce/Tests/config.yaml -v 5

And inside /home/lponce/Tests/config.yaml I define that Kiali is running out of the cluster with rest of proxies:

server:
  address: localhost
  port: 8000
  static_content_root_directory: /home/lponce/Tests/kiali-static-files
in_cluster: false
deployment:
  accessible_namespaces:
  - "**"
extensions:
  threescale:
    adapter_name: threescale
    adapter_port: 3333
    adapter_service: threescale-istio-adapter
    enabled: true
external_services:
  prometheus:
    url: http://localhost:19090
  tracing:
    enabled: true
    in_cluster_url: http://localhost:16686/jaeger
    url: http://localhost:16686/jaeger
    namespace: istio-system
    port: 443
    service : jaeger-query    
    auth:
      insecure_skip_verify: true
      password: password if needed
      type: basic
      use_kiali_token: false
      username: internal
  grafana:
    url: http://grafana-istio-system.127.0.0.1.nip.io
auth:
  strategy: anonymous
kubernetes_config:
  cache_enabled: true
  cache_duration: 300
  cache_namespaces:
  - .*
  cache_token_namespace_duration: 120  

Note that this is a config.yaml that we will change a lot when adding/testing new things.

Now you can run your Kiali process and it will be ready on localhost:8000.

Launch a Kiali front-end

The Kiali back-end process is running but it's not serving the UI.

For front-end we will start a built-in server that will serve the UI pointing to your back-end process.

The only required step is to add the proxy to the package.json:

--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
     "Instead update 'web_root' in Kaili config map in OpenShift console."
   ],
   "homepage": "./",
+  "proxy": "http://localhost:8000",
   "bugs": {
     "url": "https://issues.jboss.org/projects/KIALI/issues/"
   },

And I perform the basic steps described in the Kiali UI README:

yarn install
yarn start

Then at this point, you will have on http://localhost:3000/ a Kiali instance running out of the cluster but connecting to your Minikube + Istio cluster.

Deploy Kiali in MiniKube

Once that your changes are ready a previous step before to prepare a formal Pull Request is to validate that Kiali works correctly inside the cluster.

If you have not prepared your minikube for local deployments, follow the steps defined in the README: https://github.com/kiali/kiali#running-on-openshift-or-kubernetesminikube

$ minikube addons enable registry
$ minikube addons enable ingress
$ echo "$(minikube ip) kiali" | sudo tee -a /etc/hosts

Then you can start the process to build the images based on your local branches and deploy on your Minikube cluster. I usually have these steps in a helper script like this:

#!/usr/bin/env bash
KIALI=$HOME/Projects/gopath/src/github.com/kiali/kiali

KIALI_UI=$HOME/Projects/repos/kiali-ui

cd $KIALI

export CLUSTER_TYPE=minikube
export CONSOLE_VERSION=local
export CONSOLE_LOCAL_DIR=$KIALI_UI
export DORP=podman

make clean build cluster-push operator-create kiali-create

Note that I need to point to my local repos and I don't use docker but podman.

You should check if Kiali pod has restarted :

$ kubectl get pods -n istio-system
NAME                                      READY   STATUS    RESTARTS   AGE
grafana-5f798469fd-8p64g                  1/1     Running   0          109m
istio-citadel-6d6cbfdddb-k62z9            1/1     Running   0          109m
istio-egressgateway-cc5d84bb7-v8nfm       1/1     Running   0          109m
istio-galley-f65ffd68d-vvsb9              1/1     Running   0          109m
istio-ingressgateway-5db78457f5-zf8gh     1/1     Running   0          109m
istio-pilot-677746c74c-pj48m              1/1     Running   0          109m
istio-policy-745ff9fd59-jg8pv             1/1     Running   2          109m
istio-sidecar-injector-75ff97b4d8-jvh92   1/1     Running   0          109m
istio-telemetry-7b84df9f9-b8qft           1/1     Running   2          109m
istio-tracing-cd67ddf8-6mxrl              1/1     Running   0          109m
kiali-f77d84c67-6ddf4                     1/1     Running   0          46s
prometheus-586d4445c7-4dtp2               1/1     Running   0          109m

To access to the Kiali deployed in the cluster you can perform several ways (defining a formal Ingress route) or as similar as other services: adding a proxy to the service:

kubectl port-forward svc/kiali 20001:20001 -n istio-system

Then, at this point you have deployed your changes in the cluster and be available on https://localhost:20001/

Note that if you want to update the image (no changes in the operator) you can perform

make clean build cluster-push kiali-reload-image

Prepare your PR and contact Kiali maintainers if you need help

I hope these steps were useful in some way. There is nothing new and everything is better and extended described in Kiali READMEs but I think some times having a short summary helps to jump on the project.

Also, probably most of these steps can be done in a different way, this is just a way to work :-), take what it helps and leave me a comment (or better, a PR to our README !) if something can be improved.

Kiali maintainers can be reached out in Github

https://github.com/kiali/kiali/issues

And also in the old IRCs servers https://webchat.freenode.net/#kiali

Slack is also welcome, but you know https://xkcd.com/1782/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment