How do I run gitlab on kubernetes?

746 Views Asked by At

The task I carreid out ↓

  1. Hyper-V, Ubuntu 20.04, k8s 1.23.6, Docker 20.10.14 Installation

  2. Set up a K8s Cluster(Control Plane 1EA, Worker node 1EA)

  3. kubectl apply nginx deployment, nginx service (for test gitlab on k8s)

nginx-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  type: NodePort     
  ports:
  - port: 80     
    targetPort: 80   
    protocol: TCP
    name: http
  selector:
    app: nginx
nginx-deployment.yaml

apiVersion: apps/v1           
kind: Deployment              
metadata:
  name: nginx-deployment      
  labels:
    app: nginx               
spec:                         
  replicas: 3                 
  selector:                  
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:                 
        app: nginx
    spec:
      containers:             
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

  1. The nginx worked well. But gitlab has a problem.
gitlab-deployment.yaml

apiVersion: apps/v1           
kind: Deployment              
metadata:
  name: gitlab-deployment      
  labels:
    app: gitlab                
spec:                         
  replicas: 1                
  selector:                   
    matchLabels:
      app: gitlab
  template:
    metadata:
      labels:                 
        app: gitlab
    spec:
      containers:             
      - name: gitlab
        image: gitlab/gitlab-ee:latest
        ports:
        - containerPort: 9088
        - containerPort: 10022

gitlab-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: gitlab-svc
  labels:
    app: gitlab
spec:
  type: NodePort     
  ports:
  - port: 9088     
    targetPort: 9088
    name: http
  - port : 10022
    targetPort: 10022
    name: ssh
  selector:
    app: gitlab

  1. modify gitlab.rb file (etc/gitlab/gitlab.rb in k8s pod) . . . external_url 'http://gitlab.example.com:9088 . . gitlab_rails['gitlab_shell_ssh_port'] = 10022" . . .

  2. Input url workernodeIP:NodePort(gitlabsvc) but can't access.. The port of the container in the pod does not open either.

I don't use helm, EKS, GKS, etc. After installing Kubernetes on my hyper-v virtual machine, I want to run gitlab on it. (Like running a gitlab image with a docker) I only want to run gitlab locally using Kubernetes and gitlab images......

1

There are 1 best solutions below

2
On

If your pod is running correctly try:

kubectl port-forward pod/NAME_OF_THE_POD 8080:9088 

... On your local machine browser to check if the service works properly.

If this work, do the same with the service

kubectl port-forward service/gitlab-svc 8080:9088

The nodePort service type expose the application on the port specified of your worker node machine. If both above commands worked try to check network issues.

Please answer my comments under your questions, that way I can give you more help