Setting Up a Git Repository on Kubernetes Nodes and Performing Basic Git Operations
This guide walks through preparing the Linux environment on Kubernetes master and node machines, creating a bare Git repository, configuring SSH access, cloning the repository, and demonstrating core Git commands such as add, commit, status, diff, and push to a remote server.
1. System environment preparation
Install Git on both the master (192.168.20.40) and client (192.168.20.39) nodes:
[root@k8s-master ~]# yum -y install git [root@k8s-node3 ~]# yum -y install git2. Create a bare Git repository on the master
Create a directory, add a dedicated user, set ownership, and initialize a bare repository:
[root@k8s-master ~]# mkdir merge.git [root@k8s-master ~]# useradd git [root@k8s-master ~]# passwd git [root@k8s-master ~]# chown -Rf git:git merge.git [root@k8s-master ~]# cd merge.git/ [root@k8s-master merge.git]# git --bare initThe repository is now ready for SSH access.
3. Configure SSH keys and clone the repository
On the client node generate an SSH key pair and copy the public key to the master:
[root@k8s-node3 ~]# ssh-keygen [root@k8s-node3 ~]# ssh-copy-id 192.168.20.40Clone the empty repository:
[root@k8s-node3 ~]# git clone [email protected]:/root/merge.gitConfigure global Git user information:
[root@k8s-node3 ~]# git config --global user.name "hahashen" [root@k8s-node3 ~]# git config --global user.email [email protected] [root@k8s-node3 ~]# git config --global core.editor vim4. Basic Git workflow (add, commit, status, diff)
Create a file and add it to the staging area:
[root@k8s-node3 ~]# cd merge/ [root@k8s-node3 merge]# echo "hahashen update" > index.html [root@k8s-node3 merge]# git add index.htmlModify the file after staging: [root@k8s-node3 merge]# echo "please tell me " >> index.html Commit the staged changes: [root@k8s-node3 merge]# git commit -m "add the index file" Check repository status: [root@k8s-node3 merge]# git status View differences between the working file and the last commit: [root@k8s-node3 merge]# git diff index.html After further edits, add and commit again:
[root@k8s-node3 merge]# git add index.html [root@k8s-node3 merge]# git commit -m "added update"5. Push the local commits to the remote repository
Define the remote server and push the master branch:
[root@k8s-node3 merge]# git remote add server [email protected]:/root/merge.git [root@k8s-node3 merge]# git push -u server masterThe push operation counts, compresses, and writes objects, creating the remote master branch that tracks the local master.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
