Setup a Private Git-Repository in Kubernetes
Should there be a need for a private Git-repository on your Kubernetes cluster, this is the right place to learn how to set it up.
Gitea will be used as repository. It comes with a neatly maintained Helm-chart which makes life much easier.
If not done already, Helm needs to be installed first.
Helm Installation #
There are several ways how to install Helm.
I am on macOS and can either install it with a 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 by using homebrew
, which is the even quicker way:
brew install helm
Gitea Installation #
The chart-repo needs to be added first:
helm repo add gitea-charts https://dl.gitea.io/charts/
In case no default values have to be overwritten, then installing Gitea is as simple as running:
helm install gitea gitea-charts/gitea
By default, Gitea is configured as headless. I needed an internal IP-address though.
Therefore I have created the file gitea-values.yaml
service:
http:
type: ClusterIP
port: 3000
clusterIP:
ssh:
type: ClusterIP
port: 22
clusterIP:
Running an installation with these values being overwritten is being done with the following command:
helm install --values gitea-values.yaml gitea gitea-charts/gitea
The result should look something like 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
Neat, they even provide the command how-to forward the pods port to ones local machine:
kubectl --namespace default port-forward svc/gitea-http 3000:3000
Gitea is up and running and can be accessed with the local workstations web-browser under localhost:3000
.
IMAGE 00-gitea
The password of the initial admin user gitea_admin
can be found in the values.yaml
of the helm chart: r8sA8CPHD9!bt6d
IMAGE 01-gitea
Adding a First Project #
A new repository is created by pressing the “+"-button and selecting “New Repository”
IMAGE 02-gitea
A couple of values have to be filled out, e.g. the owner has to be chosen and the repository name provided.
IMAGE 03-gitea
When ready, press “Create Repository”
IMAGE 04-gitea
The repository is ready and files can be added.
When clicking on the repository name all steps are show what has to be done to add files to the new repository.
IMAGE 05-gitea
Therefore I have created a new project on my local workstation
$ mkdir my-java-project
$ cd my-java-project/
$ touch README.md
Initialised the local repository
$ git init
Initialized empty Git repository in /Users/username/my-java-project/.git/
Added all the files and committed them:
$ 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
For now everything is just in the local repository. In order to push everything to the remote private repository the following commands have to be performed:
$ 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://[email protected]: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!
IMAGE 06-gitea