How to install and set up ChartMuseum in Linux

ChartMuseum is an open-source Helm Chart Repository server written in Go (Golang), with support for cloud storage backends, including Google Cloud Storage, Amazon S3, Microsoft Azure Blob Storage, Alibaba Cloud OSS Storage and Openstack Object Storage.

It works as a valid Helm Chart Repository, and also provides an API for uploading charts.

In this guide we will learn how to install Chart Museum in a Linux server.

Checkout:

Step 1: Download the chartmuseum binary

Chartmuseum is available as a single compressed binary that can be downloaded, extracted and copied to the bin directory.

Let us download the package using this command. As of the writing of this guide the latest version is v0.14.0, replace that with the latest version. Check from the release page here.

cd /tmp
curl -LO https://get.helm.sh/chartmuseum-v0.14.0-linux-amd64.tar.gz

Then extract the package:

tar -xzvf chartmuseum-v0.14.0-linux-amd64.tar.gz

Finally, move the binary to the executable binary directory:

mv /tmp/linux-amd64/chartmuseum /usr/local/bin/chartmuseum
rm  -rf /tmp/linux-amd64

Step 2: Create a systemd service file

We will need to find a way to run the chartmuseum service. Systemd allows us to run the service and manage it easily.

First create required charts directory:

mkdir /opt/charts
chown rocky:rocky /opt/charts

Then let’s open the systemd file for chartmuseum.

sudo vim /etc/systemd/system/chartmuseum.service

Add this content to the file:

[Unit]
Description=Chartmuseum server

[Service]
Type=simple
User=rocky
Group=rocky

Environment=DEBUG=1
Environment=STORAGE=local
Environment=STORAGE_LOCAL_ROOTDIR=/opt/charts

WorkingDirectory=/tmp
ExecStart=/usr/local/bin/chartmuseum --port=9080

[Install]
WantedBy=multi-user.target

When the service starts, we are running the command /usr/local/bin/chartmuseum --port=9080 which will expose the service in port 9080. We are also exporting some environment variables that will define the chart storage type and path.

Step 3: Start and enable the service

Since we created a new systemd service, let us start by doing a daemon reload:

sudo systemctl daemon-reload

Then start using this command

sudo systemctl start chartmuseum

Confirm the status to ensure its running as expected using this command:

$ sudo systemctl status chartmuseum
● chartmuseum.service - Chartmuseum server
     Loaded: loaded (/etc/systemd/system/chartmuseum.service; enabled; vendor preset: disabled)
     Active: active (running) since Sun 2022-04-03 20:46:16 UTC; 22s ago
   Main PID: 7617 (chartmuseum)
      Tasks: 5 (limit: 4915)
     CGroup: /system.slice/chartmuseum.service
             └─7617 /usr/local/bin/chartmuseum --port=9080

Apr 03 20:46:16 opensusesrv systemd[1]: Started Chartmuseum server.
Apr 03 20:46:16 opensusesrv chartmuseum[7617]: 2022-04-03T20:46:16.147Z        DEBUG        index-cache.yaml loaded        {"repo": ""}
Apr 03 20:46:16 opensusesrv chartmuseum[7617]: 2022-04-03T20:46:16.148Z        INFO        Starting ChartMuseum        {"host": "0.0.0.0", "port": 9080}
Apr 03 20:46:16 opensusesrv chartmuseum[7617]: 2022-04-03T20:46:16.148Z        DEBUG        Starting internal event listener

Enable the service to start on boot

sudo systemctl enable chartmuseum

Step 4: Accessing the service

Head to http://server_ip:9080 to access the service. You will need to enable the service port if you are accessing in a remote server.

If you have firewalld installed and enabled, you will need to enable the service port. Enable using this command:

sudo firewall-cmd --permanent --add-port=9080/tcp
sudo firewall-cmd --reload

If you see the page with this content:

Welcome to ChartMuseum!
If you see this page, the ChartMuseum web server is successfully installed and working.

Then everything is set up.

Step 5: Adding Nginx for access

You can add nginx to proxy the request so you do not have to use the server IP address. First install Nginx in your server.

# For RHEL based:
sudo dnf install -y nginx

# For Ubuntu and Debian based
sudo apt install -y nginx

Next let us create an Nginx config file for chartmuseum. Open the config file with your editor:

sudo vim /etc/nginx/conf.d/chartmuseum.conf

Then add this content:

server {
    listen 80;
    server_tokens off;
    client_max_body_size 100M;
    server_name chartmuseum.citizix.com;

    ignore_invalid_headers off;

    if ($host !~* ^(chartmuseum.citizix.com)$ ) {
        return 444;
    }

    location / {
        send_timeout            600;
        proxy_read_timeout      600;
        proxy_send_timeout      600;
        proxy_connect_timeout   600;
        proxy_redirect          off;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Host $server_name;
        proxy_set_header        X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:9080;
    }
}

Then start and enable nginx

sudo systemctl start nginx
sudo systemctl enable nginx

You can now access the service using this address http://chartmuseum.citizix.com instead of the server ip and port

Step 6: Working with helm museum

Once everything is set up, we can test if our repository is working as expected. You will need to have helm installed locally to proceed.

First, add the new repo that we created:

helm repo add citizix http://chartmuseum.citizix.com

We can confirm the addition by listing:

➜ helm repo list | grep citizix
citizix         	http://chartmuseum.citizix.com

Let us create new chart called app:

➜ helm create app
Creating app

Lint to validate that it is fine:

❯ helm lint app/

==> Linting app/
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed

We can then push the new app chart to our repository. You will need the helm push plugin. Install push plugin using this command:

helm plugin install https://github.com/chartmuseum/helm-push

Then push the app repo:

➜ helm cm-push app citizix
Pushing app-0.1.0.tgz to citizix...
Done.

To confirm that it was pushed successfully:

helm repo update

Then

➜ helm search repo citizix
NAME     	CHART VERSION	APP VERSION	DESCRIPTION
citizix/app	0.1.0        	1.16.0     	A Helm chart for Kubernetes

Conclusion

In this guide we were able to install, setup and test our set up of chartmuseum on a linux server. For more information please checkout the chartmuseum page.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy