[Workshop] Learn how to integrate your charm with COS-Lite all the way

Summary on what we talked about on the workshop


This is a summary of what we talked about on the workshop Learn how to integrate your charm with COS-lite all the way


Notice that this is an example setup to be able to start tinkering with COS-lite

We started of by creating a bridge in netplan to separate the network for COS-lite.

Edit /etc/netplan/network-configuration-file.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    wlp9s0:
      dhcp4: true
      dhcp6: true
  bridges:
    k8sbr0:
      interfaces:
        - wlp9s0
      addresses:
        - 10.10.88.1/24
      routes:
        - to: 0.0.0.0/0
          via: 10.10.88.1
      nameservers:
        addresses:
          - 10.10.88.1
      dhcp4: false
      dhcp6: false



After that we continued with installing microk8s from snap

Commands used in video

Metallb is a load balancer and your gateway in to traefik. Traefik then points to services inside kubernetes. There is 3 ways to set IP-addresses, examples: 1. Static-IP: 192.168.0.3/32, 2. Subnet: 192.168.0.0/24, 3. IP-range: 192.168.0.10-192.168.0.20

1
2
$ sudo snap install microk8s --classic
$ microk8s.enable dns hostpath-storage metallb:10.10.88.2-10.10.88.10



Next, we bootstrapp a juju controller on the microk8s cloud

Commands used in video

1
$ juju bootstrap microk8s <controller-name>

If you instead want to add the microk8s cloud to an already deployed controller use this commnads:

1
$ microk8s.config | juju add-k8s <cloud-name> --controller <controller-name>



After bootstrapping a new controller, we add a new model for COS-lite and then deploying COS stack inside that.

Commands used in video

1
2
$ juju add-model <model-name>
$ juju deploy cos-lite --trust --channel edge

To deploy COS-lite using overlays (pre-defined configurations), we can add --overlay to the command when deploying. Here are some overlay examples

Commands used in video

1
2
$ juju add-model <model-name>
$ juju deploy cos-lite --trust --channel edge --overlay ./path-to-overlay-file.yaml --overlay ./path-to-second-overlay-file.yaml

Traefik is a reverse proxy, it get a gateway address from the metallb, which we can use to connect to grafana, prometheus and alertmanager. We can connect to the services by using the IP-address followed by model-name and application-name like this https://10.10.88.2/cos-grafana. I’ve noticed that some applications require adding unit number as well (ex. cos-prometheus-0).

We can use actions to get the admin password to be able to login to grafana. juju run-action grafana/0 get-admin-password --wait

After having COS-lite deployed and ready, we can make offers of the endpoints needed for grafana-agent. Grafana-agent needs to be related to 3 endpoints to get out of it’s blocked state.

Commands used in video

1
2
3
4
$ juju offer grafana:grafana-dashboard [<offer-name>]
$ juju offer loki:logging [<offer-name>]
$ juju offer prometheus:receive-remote-write [<offer-name>]
$ juju status



Observed is built by @eriklonroth as a reference charm to learn what COS-lite can do. It ships with a dashboard, prometheus & loki alert rule. To be able to build it you need a clone of the repo and charmcraft. After building it we can deploy observed to a new model.

Commands used in video

1
2
$ juju add-model observed
$ juju deploy ./observed.charm



For observed to be able to send data to the COS-lite, we need to deploy are “bridge” between COS-lite and the charms. Grafana-agent is a subordinate charm that scrapes metrics, logs and dashboards and sends it to COS stack. Charms need to support grafana-agent integrations for it to work, which observed does, so lets deploy and relate grafana-agent right now.

Commmands used in video

1
2
3
$ juju deploy grafana-agent --channel edge
$ juju relate grafana-agent observed
$ juju status --relations



We can now see that grafana-agent is deployed under observed but is showing a blocked status. To get out of the blocked status we need to consume the offers we made previously and relate those to grafana-agent.

Commmands used in video

1
2
3
4
5
6
7
8
$ juju find-offers <controller-name>:
$ juju consume [<controller-name>]:admin/cos.grafana-dashboard [<saas-name>]
$ juju consume [<controller-name>]:admin/cos.loki-logging [<saas-name>]
$ juju consume [<controller-name>]:admin/cos.prometheus-rrw [<saas-name>]
$ juju status
$ juju relate grafana-agent grafana-dashboard
$ juju relate grafana-agent loki-logging
$ juju relate grafana-agent prometheus-rrw



After previous section it should now be possible to find new dashboards and alert rules in grafana. There should also be a dashboard called Observed Microsample. To trigger alert rules we can start to call observed charms api.

Curl Observed

1
2
3
4
$ curl http://<IP-ADDRESS-FOR-OBSERVED>:8080 # to return online
$ curl http://<IP-ADDRESS_FOR_OBSERVED>:8080/whatever # to return 404
# Example to trigger alerts for invalid api calls
$ while 1>0; do curl http://10.10.99.213:8080/fire; sleep 0.5; done



In the observed repo you can find examples configurations for alertmanager that can enable integration with other services like slack and pagerduty to receive notifications. Use following command to push a configuration file to alertmanager.

1
$ juju config alertmanager config_file=@/path/to/file.yaml

To show or check current configuration:

1
2
$ juju run-action alertmanager/0 show-config
$ juju run-action alertmanager/0 check-config