Friday, December 27, 2024
Google search engine
HomeGuest BlogsMonitor Docker Containers and Kubernetes using Weave Scope

Monitor Docker Containers and Kubernetes using Weave Scope

Weave Scope is a monitoring tool for Docker and Kubernetes clusters. It allows you to monitor your on-premise Docker host as well as Kubernetes cluster in realtime.

You can visualize the utilization of your containers or your cluster on a web dashboard.

Weave Scope can also be used to manage your docker containers which includes operations such as start,stop containers. You can also access the container shell from Weave Scope.

This guide shall cover how to install Weave Scope on an on-premise Docker host and on a Kubernetes cluster.

Install Weave Scope on Docker host

Run the following commands on a docker host to install Weave Scope:

sudo curl -L git.io/scope -o /usr/local/bin/scope
sudo chmod a+x /usr/local/bin/scope

Launch Weave Scope:

$ scope launch

Sample output:

# scope launch
7807556aed11a523d5ec2dc651a438aa6bae7df1a2d76dd440c82530b475c49d
Scope probe started
Weave Scope is listening at the following URL(s):
  * http://172.16.34.12:4040/

You can now access Weave scope on http://server-IP:4040

The dashboard will show the containers running on your host and there are several other options to manage and/or monitor your host:

weavescope docker containers

To manage your containers, click one one of them, you will be presented with an interface where you can view the metrics of the container and also do various operations on the container such as start,stop, pause etc. You can also execute the container’s shell as shown below:

monitor and manage docker using weave scope

General metrics are available at the Table tab:

manage docker containers with weave scope

Install Weave Scope on Kubernetes Cluster

We shall deploy Weave Scope on our K8s cluster and demonstrate how to monitor and manage your cluster using the tool.

Weave Scope service will be exposed via NodePort in this tutorial. It is however NOT advisable to expose Weave Scope service to the internet as this will leave your cluster vulnerable to anyone who can access it.

This means that you should only expose the service if you are running on a local network.

Deploy Weave Scope using the script below:

VER=$(curl -s https://api.github.com/repos/weaveworks/scope/releases/latest|grep tag_name|cut -d '"' -f 4|sed 's/v//')
kubectl apply -f https://github.com/weaveworks/scope/releases/download/v$VER/k8s-scope.yaml

Sample output:

namespace/weave created
clusterrole.rbac.authorization.k8s.io/weave-scope created
clusterrolebinding.rbac.authorization.k8s.io/weave-scope created
deployment.apps/weave-scope-app created
daemonset.apps/weave-scope-agent created
deployment.apps/weave-scope-cluster-agent created
serviceaccount/weave-scope created
service/weave-scope-app created

This deploys 2 pods,Weave-scope-app and Weave-scope-agent. The Weave-scope-agent runs on every node.

The deployment is also confined in weave namespace.

To see if the deployments have started successfully:

$ kubectl get pods -n weave
NAME                                         READY   STATUS    RESTARTS   AGE
weave-scope-agent-24dxm                      1/1     Running   0          4m17s
weave-scope-agent-88ld2                      1/1     Running   0          4m17s
weave-scope-agent-c8bfc                      1/1     Running   0          4m17s
weave-scope-agent-d5whl                      1/1     Running   0          4m17s
weave-scope-agent-dlq5p                      1/1     Running   0          4m17s
weave-scope-agent-fzftp                      1/1     Running   0          4m17s
weave-scope-agent-gh6cr                      1/1     Running   0          4m17s
weave-scope-agent-j9n2z                      1/1     Running   0          4m17s
weave-scope-agent-mh9v8                      1/1     Running   0          4m17s
weave-scope-agent-ptgfc                      1/1     Running   0          4m17s
weave-scope-agent-xf79f                      1/1     Running   0          4m17s
weave-scope-app-658845597b-hthgf             1/1     Running   0          4m17s
weave-scope-cluster-agent-84f7b6767c-mcjf4   1/1     Running   0          4m17s

We then need to obtain the NodePort that has been exposed using the command below:

$ kubectl get service -n weave
NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
weave-scope-app   ClusterIP   10.233.40.222   <none>        80/TCP    35s

If you need the Service to be accessible from outside you can expose using NodePort or LoadBalancer service types.

# Note: Do not expose the Scope service to the Internet, e.g. by changing the type to NodePort or LoadBalancer. Scope allows anyone with access to the user interface control over your hosts and containers.
# Information given here is just reference for internal deployments

## Expose using Load Balancer ###
kubectl --namespace weave patch svc weave-scope-app -p '{"spec": {"type": "LoadBalancer"}}'

## Expose using NodePort ###
kubectl --namespace weave patch svc weave-scope-app -p '{"spec": {"type": "NodePort"}}'

Confirm service information.

$ kubectl get service -n weave
NAME              TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)        AGE
weave-scope-app   LoadBalancer   10.233.40.222   192.168.1.38   80:32435/TCP   4m46s

For Port forwarding use:

kubectl port-forward -n weave "$(kubectl get -n weave pod --selector=weave-scope-component=app -o jsonpath='{.items..metadata.name}')" 4040
# Then access on localhost:4040

We can now access the dashboard through the controller IP and the NodePort.

weave scope kubernetes dashboard

In the image above, we can visualize our Kubernetes cluster and also manage it.

You can check the logs of different deployments from the dashboard.

weave scope k8s pod logs

From the dashboard, we can also check the health and status of pods.

weave scope kubernetes logs

Books For Learning Kubernetes Administration:

Conclusion

Weave Scope is easy to install and use. It has interesting features that you would love to explore as a system administrator.

Check out these other interesting tools on our site:

How To Install Netdata on Kubernetes using Helm

RELATED ARTICLES

Most Popular

Recent Comments