Kubernetes Scaling with Juju (OSM)

Emin Aktaş
5 min readMar 11, 2021

In this article, I will briefly show you how you can instantiate a K8s service with OSM, scale it up and run actions with Juju.

I am assuming that you have knowledge of OSM, K8s and Juju.

To install OSM you can go here: https://osm.etsi.org/docs/user-guide/01-quickstart.html#installing-osm

The followings are the sample files for instantiating the KNF service from OSM Repository.

https://osm.etsi.org/gitlab/vnf-onboarding/osm-packages/-/tree/master/charm-packages/native_k8s_charm_ns

https://osm.etsi.org/gitlab/vnf-onboarding/osm-packages/-/tree/master/charm-packages/native_k8s_charm_vnf

In this sample, we are using Charm bundle to learn more about it. You can read here: https://juju.is/docs/charm-bundles

Of course you need a K8s cluster added to OSM environment. If you haven’t you can read this article to create a K8s Cluster. In the article just go to “K8s Cluster Setup” topic.

When you are done creating K8s cluster or if you have already, you can use this command to add the K8s Cluster to your OSM.

$ osm k8scluster-add \    --creds <path to k8s config file> \    --vim <VIM name> \    --k8s-nets "{(k8s_net1: <VIM network name>)}" \    --version <Kubernetes version> \    --namespace <namespace name> \    --description "<description>" \    <name>

To instantiate the KNF service:

$ osm ns-create --ns_name <name the network service> --nsd_name <name of the ns package> --vim_account <vim name> --config '{vld: [ {name: <name vld>, vim-network-name: "<vim network name>"} ] }'
# Example command used for this article
$ osm ns-create --ns_name nativek8s-test-1 --nsd_name native_k8s_charm-ns --vim_account osmtest --config '{vld: [ {name: osmtest-public, vim-network-name: "<vim network name>"} ] }'

When your ‘ns state’ is READY, we can continue on the article.

# You can check your ns instance informatin with this command.
$ osm ns-list

Ok. Rest is easy. Let’s see what we have in the Juju model.

# -m refers for model name so, OSM sets the ns instance id as model name. You can either use -m flag or 'juju switch <model-name>' command to work on the model that we are working on.$ juju status -m <model name>$ juju status -m c5112091-b6a2-4f15-bccf-009b0b86beb4

We are seeing Model, App and Unit. You can read the concepts and terms about Juju here: https://juju.is/docs/concepts-and-terms

Time to check what we can do with this model.

First, Let’s see what we have here with the Actions. When we call the following command we will see the supported actions of the nginx application.

$ juju actions <application name> -m <model name>$ juju actions nginx -m c5112091-b6a2-4f15-bccf-009b0b86beb4

Use the command to check out the details for the actions. The sample we are using includes only one method that only changes the title of the web page.

$ juju actions <application name> --schema --format yaml -m <model name>$ juju actions nginx --schema --format yaml -m c5112091-b6a2-4f15-bccf-009b0b86beb4

Before we scale the Application let’s run the action for the first unit which is the only one we have here for the moment.

$ juju run-action <unit name> <actions name> <parameter name=parameter value> -m <model name>$ juju run-action nginx/0 changecontent customtitle=After-Run-Action -m c5112091-b6a2-4f15-bccf-009b0b86beb4

For this example, Units are the containers. So, the first unit is name nginx/0 that is this pod ‘nginx-78c4d7bdb9–8rqx8’. So, when we run action for the specific unit it runs the action for the specific container.

$ kubectl get pods -n <namespace which same with model name>$ kubectl get pods -n c5112091-b6a2-4f15-bccf-009b0b86beb4

Let me show you what we have before running action and after running action.

$ kubectl exec -it -n <namespace same with model name> -- curl localhost$ kubectl exec -it -n c5112091-b6a2-4f15-bccf-009b0b86beb4 nginx-78c4d7bdb9-8rqx8 -- curl localhost
Before
After

We just learned how the actions work.

Time to scale the application which is ‘nginx’. We have seen the application when we call this juju status -m <model name>above.

For scaling the Pod we use the following K8s CLU command kubectl scale deployment <deployment name> --replicas=<number of pod>. This is not much different in Juju. The below command is for scaling the application. Juju adds another unit than we see the nginx deployment is scaled.

$ juju scale-application <application name> <total number of units> -m <model name>$ juju scale-application nginx 2 -m c5112091-b6a2-4f15-bccf-009b0b86beb4

New added unit is same as the first unit. Hence, you can run actions with the new unit but this unit only responsible for one pod.

Let’s check our environment again with the following commands.

$ juju status -m c5112091-b6a2-4f15-bccf-009b0b86beb4
$ kubectl get pods -n c5112091-b6a2-4f15-bccf-009b0b86beb4
$ kubectl get deploy -n c5112091-b6a2-4f15-bccf-009b0b86beb4

As you can see we have two units and two pods.

Let’s run actions for the scaled pod. Like we did before let’s see before and after.

$ juju run-action nginx/1 changecontent customtitle=Run-Action-Scaled-Pod -m c5112091-b6a2-4f15-bccf-009b0b86beb4
Before
After

That’s it. Thank you for reading.

Other references that might be helpful:

https://discourse.charmhub.io/t/scaling-applications/1075

https://juju.is/docs/deploying-applications

--

--