Kubernetes, GitLab and You

This is a list of useful information regarding Kubernetes that the GitLab Support Team sometimes uses while troubleshooting. GitLab is making this public, so that anyone can make use of the Support team's collected knowledge

CAUTION: Caution: These commands can alter or break your Kubernetes components so use these at your own risk.

If you are on a paid tier and are not sure how to use these commands, it is best to contact Support and they will assist you with any issues you are having.

Generic Kubernetes commands

bash gcloud auth login

bash # for minikube: minikube dashboard —url # for non-local installations if access via Kubectl is configured: kubectl proxy

bash kubectl cp file-name pod-name:./destination-path

bash kubectl get events -w --all-namespaces

bash kubectl logs <pod-name> --previous

NOTE: Note: No logs are kept in the containers/pods themselves, everything is written to stdout. This is the principle of Kubernetes, read Twelve-factor app for details.

GitLab-specific Kubernetes information

bash kubectl logs gitlab-unicorn-7656fdd6bf-jqzfs -c unicorn

```bash # all containers in the unicorn pods kubectl logs -f -l app=unicorn --all-containers=true --max-log-requests=50

# only the unicorn containers in all unicorn pods kubectl logs -f -l app=unicorn -c unicorn --max-log-requests=50 ```

bash kubectl logs -f -l release=gitlab --all-containers=true --max-log-requests=100

bash kubectl get events -w --namespace=gitlab

```bash # find the pod kubectl get pods | grep task-runner

# enter it kubectl exec -it bash

# open rails console # rails console can be also called from other GitLab pods /srv/gitlab/bin/rails console

# source-style commands should also work /srv/gitlab && bundle exec rake gitlab:check RAILS_ENV=production

# run GitLab check. Note that the output can be confusing and invalid because of the specific structure of GitLab installed via helm chart /usr/local/bin/gitlab-rake gitlab:check

# open console without entering pod kubectl exec -it /srv/gitlab/bin/rails console

# check the status of DB migrations kubectl exec -it /usr/local/bin/gitlab-rake db:migrate:status ```

You can also use gitlab-rake, instead of /usr/local/bin/gitlab-rake.

bash # find the name of the secret containing the password kubectl get secrets | grep initial-root # decode it kubectl get secret <secret-name> -ojsonpath={.data.password} | base64 --decode ; echo

bash kubectl exec -it <task-runner-pod-name> -- /srv/gitlab/bin/rails dbconsole -p

bash helm status name-of-installation

```bash helm repo upgrade

# get current values and redirect them to yaml file (analogue of gitlab.rb values) helm get values > gitlab.yaml

# run upgrade itself helm upgrade -f gitlab.yaml ```

After https://gitlab.com/gitlab-org/charts/gitlab/issues/780 is fixed, it should be possible to use Updating GitLab using the Helm Chart for upgrades.

Installation of minimal GitLab config via Minukube on macOS

This section is based on Developing for Kubernetes with Minikube and Helm. Refer to those documents for details.

bash brew install kubernetes-cli

bash brew cask install minikube

bash minikube start --cpus 3 --memory 8192 # minimum amount for GitLab to work minikube addons enable ingress minikube addons enable kube-dns

bash brew install kubernetes-helm helm init --service-account tiller

bash helm repo add gitlab https://charts.gitlab.io helm install --name gitlab -f <path-to-yaml-file> gitlab/gitlab

If you want to modify some GitLab settings, you can use the above-mentioned config as a base and create your own yaml file.