If you need a private Git repository on your Kubernetes cluster, this guide shows how to set one up.

We will use Gitea as the repository server. It provides a well-maintained Helm chart, which simplifies installation.

If you haven’t already, install Helm first.

Helm Installation

There are several ways to install Helm.

On macOS you can use the installation script:

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
cat get_helm.sh

Or install with Homebrew (quicker ):

brew install helm

Gitea Installation

First add the chart repo:

helm repo add gitea-charts https://dl.gitea.io/charts/

If you don’t need to override any defaults, install Gitea with:

helm install gitea gitea-charts/gitea

By default, Gitea is configured as headless. I needed an internal ClusterIP instead, so I created gitea-values.yaml:

service:
 http:
 type: ClusterIP
 port: 3000
 clusterIP:
 ssh:
 type: ClusterIP
 port: 22
 clusterIP:

Install with the custom values file:

helm install --values gitea-values.yaml gitea gitea-charts/gitea

The output should look similar to this:

NAME: gitea
LAST DEPLOYED: Thu Feb 18 21:30:29 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
 echo "Visit http://127.0.0.1:3000 to use your application"
 kubectl --namespace default port-forward svc/gitea-http 3000:3000

They even provide the command to forward the pod’s port to your local machine:

kubectl --namespace default port-forward svc/gitea-http 3000:3000

Gitea is now running and can be accessed in your browser at localhost:3000.

The initial admin user’s password (gitea_admin ) is in the chart’s values.yaml: r8sA8CPHD9!bt6d

Adding a First Project

Create a new repository by pressing the ”+” button and selecting “New Repository”.

Fill in the required fields, e.g., choose the owner and provide a repository name.

When ready, press “Create Repository”.

The repository is created and files can be added. Clicking the repository name shows the steps to add files to the new repo.

I created a new project locally:

$ mkdir my-java-project
$ cd my-java-project/
$ touch README.md

Initialize the local repository:

$ git init
Initialized empty Git repository in /Users/username/my-java-project/.git/

Add and commit the files:

$ git add README.md
$ git commit -m "first commit"
[master (root-commit) 1689222] first commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md

Now push the local repository to the remote private repository:

$ git remote add origin http://127.0.0.1:3000/gitea_admin/my-java-project.git

$ git push -u origin master

Username for 'http://127.0.0.1:3000': gitea_admin
Password for 'http://gitea_admin@127.0.0.1:3000':
Counting objects: 3, done.
Writing objects: 100% (3/3), 220 bytes | 220.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:. Processing 1 references
remote: Processed 1 references in total
To http://127.0.0.1:3000/gitea_admin/my-java-project.git
 * [new branch]  master -> master
Branch master set up to track remote branch master from origin.

Et voilà— everything worked!

Resources

  • Gitea: Git with a cup of tea
  • Installation with Helm (on Kubernetes)
  • Gitea Helm Chart
  • Installing Helm