Skip to content

Cloud Native Microservices - Eclipse Microprofile Reference implementation based on Kubernetes

Notifications You must be signed in to change notification settings

sirAlexander/shikanga-cloudnative-kubernetes

Repository files navigation

Eclipse MicroProfile

Optimizing Enterprise Java for a Microservices Architecture

Setup of a Local Kubernetes and Istio Dev Environment

In order to build cloud-native applications and microservices, it’s very convenient to have a local Kubernetes cluster and Istio running locally. This article describes how to install these components and some additional tools like Kiali.

Minikube

Follow the instructions to install Minikube.

Start Minikube

Note: As I’ll be running Istio along with my applications, one needs more memory and CPU than you get by default. Here are some recommended settings:

$ minikube config set cpus 4
$ minikube config set memory 8192
$ minikube config set disk-size 50g
$ minikube addons enable ingress

With all the required packages are installed. You can now start Minikube with the following command:

$ minikube start

This will download the Virtualbox image and configure Kubernetes cluster as shown below:

😄  minikube v1.6.2 on Ubuntu 18.04
✨  Automatically selected the 'virtualbox' driver (alternates: [none])
💿  Downloading VM boot image ...
    > minikube-v1.6.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s
    > minikube-v1.6.0.iso: 150.93 MiB / 150.93 MiB [-] 100.00% 19.41 MiB p/s 8s
🔥  Creating virtualbox VM (CPUs=2, Memory=2000MB, Disk=20000MB) ...
🐳  Preparing Kubernetes v1.17.0 on Docker '19.03.5' ...
💾  Downloading kubeadm v1.17.0
💾  Downloading kubelet v1.17.0
🚜  Pulling images ...
🚀  Launching Kubernetes ...
⌛  Waiting for cluster to come online ...
🏄  Done! kubectl is now configured to use "minikube"

Verifying cluster status and kubectl configuration

You can now check the cluster status with the following command:

$ kubectl cluster-info

You should get the following output:

Kubernetes master is running at https://192.168.99.100:8443
KubeDNS is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

You can also check the Kubectl default configuration with the following command:

$ kubectl config view

Below is the expected output:

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/sir_alexander/.minikube/ca.crt
    server: https://192.168.99.100:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/sir_alexander/.minikube/client.crt
    client-key: /home/sir_alexander/.minikube/client.key

To check the running nodes, run the following command:

$ kubectl get nodes

output:

NAME       STATUS   ROLES    AGE   VERSION
minikube   Ready    master   16m   v1.17.0

You can check the status of Minikube with the following command:

$ minikube status

And see the following output:

host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

You can also access the Minikube Virtualbox with the following command:

$ minikube ssh

and get:

                         _             _
            _         _ ( )           ( )
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$

Now, exit from the Virtualbox shell:

$ exit

You can also stop and delete kubernetes cluster anytime with the following command:

$ minikube stop
$ minikube delete

Access Kubernetes Dashboard

By default, Kubernetes comes with web dashboard that can be used to manage your cluster. You can list all the minikube addons with the following command:

$ minikube addons list

You should see the following output:

- addon-manager: enabled
- dashboard: disabled
- default-storageclass: enabled
- efk: disabled
- freshpod: disabled
- gvisor: disabled
- helm-tiller: disabled
- ingress: disabled
- ingress-dns: disabled
- logviewer: disabled
- metrics-server: disabled
- nvidia-driver-installer: disabled
- nvidia-gpu-device-plugin: disabled
- registry: disabled
- registry-creds: disabled
- storage-provisioner: enabled
- storage-provisioner-gluster: disabled

Next, list all the container image running in the cluster with the following command:

kubectl get pods --all-namespaces

You should see the following output:

NAMESPACE     NAME                                        READY   STATUS    RESTARTS   AGE
kube-system   coredns-6955765f44-pjzdd                    1/1     Running   0          42s
kube-system   coredns-6955765f44-q7zcd                    1/1     Running   0          42s
kube-system   etcd-minikube                               1/1     Running   0          48s
kube-system   kube-addon-manager-minikube                 1/1     Running   0          48s
kube-system   kube-apiserver-minikube                     1/1     Running   0          48s
kube-system   kube-controller-manager-minikube            1/1     Running   0          48s
kube-system   kube-proxy-2lvq8                            1/1     Running   0          42s
kube-system   kube-scheduler-minikube                     1/1     Running   0          47s
kube-system   nginx-ingress-controller-6fc5bcc8c9-4pnnn   1/1     Running   0          40s
kube-system   storage-provisioner                         1/1     Running   0          41s

Now, run the following command to get the URL of the kubernetes dashboard:

minikube dashboard --url

You should see the following output:

🔌  Enabling dashboard ...
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
http://127.0.0.1:34897/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

Your Minikube web url is now generated. Next, open your web browser and type the URL http://127.0.0.1:34897/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/. You will be redirected to the Kubernetes dashboard as shown in the following page: kubernetes-dashboard

You can now easily manage your Kubernetes cluster through your web browser.

Note: Minikube comes with it’s own Docker daemon, so that you don’t have to use Docker Desktop. You only need the ‘docker’ CLI and point it to Minikube:

$ eval $(minikube docker-env)

Istio Installation

Download Istio into your preferred location using the following command:

$ curl -L https://git.io/getLatestIstio | sh -

Follow the instructions in the terminal to set the path.

To configure the istioctl client tool for your workstation, add the /<PATH TO ISTIO DIRECTORY>/istio-1.4.2/bin directory to your environment path variable with:

$ cd `/<PATH TO ISTIO DIRECTORY>/istio-1.4.2`
$ export PATH=$PWD/bin:$PATH

Ensure minikube is started and running

Begin the Istio pre-installation verification check by running:

$ istioctl verify-install

If all is well, you should get the following output:

Checking the cluster to make sure it is ready for Istio installation...

#1. Kubernetes-api
-----------------------
Can initialize the Kubernetes client.
Can query the Kubernetes API Server.

#2. Kubernetes-version
-----------------------
Istio is compatible with Kubernetes: v1.17.0.

#3. Istio-existence
-----------------------
Istio will be installed in the istio-system namespace.

#4. Kubernetes-setup
-----------------------
Can create necessary Kubernetes configurations: Namespace,ClusterRole,ClusterRoleBinding,CustomResourceDefinition,Role,ServiceAccount,Service,Deployments,ConfigMap.

#5. SideCar-Injector
-----------------------
This Kubernetes cluster supports automatic sidecar injection. To enable automatic sidecar injection see https://istio.io/docs/setup/kubernetes/additional-setup/sidecar-injection/#deploying-an-app

-----------------------
Install Pre-Check passed! The cluster is ready for Istio installation.

To install Istio, run these commands:

$ cd /<PATH TO ISTIO DIRECTORY>/istio-1.4.2/
$ kubectl apply -f install/kubernetes/helm/istio-init/files
$ kubectl apply -f install/kubernetes/istio-demo.yaml

Make sure that all pods are running or completed before continuing. This can take several minutes when starting the pods for the first time. Be patient.

$ kubectl get pod -n istio-system

The output of the above command should show all Istio pods either running or completed before you move on.

NAME                                      READY   STATUS      RESTARTS   AGE
grafana-7797c87688-5j56c                  1/1     Running     0          3m22s
istio-citadel-65c9f49c76-xs66z            1/1     Running     0          3m21s
istio-egressgateway-5b6cbd4c96-sgxsh      1/1     Running     0          3m22s
istio-galley-c5cb9c77d-s52rl              1/1     Running     0          3m22s
istio-grafana-post-install-1.4.2-nnfmk    0/1     Completed   0          3m23s
istio-ingressgateway-7b66b7c7c-gwdrq      1/1     Running     0          3m22s
istio-pilot-7d5c97cc67-9p8lv              2/2     Running     2          3m22s
istio-policy-86775c9966-qkdxt             2/2     Running     2          3m22s
istio-security-post-install-1.4.2-kgzgt   0/1     Completed   0          3m22s
istio-sidecar-injector-59ccc94d59-mq2jg   1/1     Running     0          3m21s
istio-telemetry-68c7b4f9b8-5t2sq          2/2     Running     2          3m22s
istio-tracing-55c965d5b6-fkxs7            1/1     Running     0          3m21s
kiali-74fdc898b9-f7fjw                    1/1     Running     0          3m22s
prometheus-c8fdbd64f-6k7fw                1/1     Running     0          3m22s

In the last step enable automatic sidecar injection:

$ kubectl label namespace default istio-injection=enabled

Getting familiar with the various kubernetes tools

After the setup of Minikube and Istio you can use the following tools:

  • Kubernetes Dashboard

$ minikube dashboard
  • Jaeger Dashboard

$ kubectl port-forward -n istio-system $(kubectl get pod -n istio-system -l app=jaeger -o jsonpath='{.items[0].metadata.name}') 16686:16686

URL to Open Jaeger: http://localhost:16686

  • Grafana Dashboard

$ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=grafana -o jsonpath='{.items[0].metadata.name}') 3000:3000 &
  • Prometheus Dashboard

$ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &

URL to open Prometheus: http://localhost:9090

Kiali Installation

Run the following command to install Kiali:

$ bash <(curl -L https://git.io/getLatestKialiOperator)
  • Kiali Dashboard

$ cd /<PATH TO ISTIO DIRECTORY>/istio-1.4.2/
$ istioctl dashboard kiali

URL to open Kiali: https://localhost:<KIALI_PORT>;

To uninstall Kiali, use the following command:

$ bash <(curl -L https://git.io/getLatestKialiOperator) --uninstall-mode true