简介
GitLab社区版是免费的,和github不同,他可以免费的建立私有仓库,非常适合我们的项目开发。
为了组内的CI/CD工作,现在需要部署一个gitlab来做代码仓库。
部署
假设读者已经有一个kubernetes集群了,我这里是ocp(openshift container platform)。
gitlab官网用的是helm安装,都是chart的形式,为了方便起见,我们直接用命令行 apply yaml来部署,从IBM的sample下载的yaml,在自己的环境中部署会有问题,我修改了,下面直接把yaml贴出来。
redis.yaml:
---
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
app: gitlab
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: gitlab
tier: backend
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-claim
labels:
app: gitlab
spec:
storageClassName: gluster-dyn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: redis
labels:
app: gitlab
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: gitlab
tier: backend
spec:
containers:
- image: redis:3.0.7-alpine
name: redis
ports:
- containerPort: 6379
name: redis
volumeMounts:
- name: redis
mountPath: /data
volumes:
- name: redis
persistentVolumeClaim:
claimName: redis-claim
postgers.yaml
---
apiVersion: v1
kind: Service
metadata:
name: postgresql
labels:
app: gitlab
spec:
ports:
- port: 5432
selector:
app: gitlab
tier: postgreSQL
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-claim
labels:
app: gitlab
spec:
storageClassName: gluster-dyn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: postgresql
labels:
app: gitlab
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: gitlab
tier: postgreSQL
spec:
containers:
- image: postgres:9.6.2-alpine
name: postgresql
env:
- name: POSTGRES_USER
value: gitlab
- name: POSTGRES_DB
value: gitlabhq_production
- name: POSTGRES_PASSWORD
value: gitlab
ports:
- containerPort: 5432
name: postgresql
volumeMounts:
- name: postgresql
mountPath: /var/lib/postgresql/data
subPath: postgres
volumes:
- name: postgresql
persistentVolumeClaim:
claimName: postgres-claim
gitlab.yaml:
---
apiVersion: v1
kind: Service
metadata:
name: gitlab
labels:
app: gitlab
spec:
ports:
- name: gitlab-ui
port: 80
protocol: TCP
targetPort: 30080
- name: gitlab-ssh
port: 22
protocol: TCP
targetPort: 22
selector:
app: gitlab
tier: frontend
type: ClusterIP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gitlab-claim
labels:
app: gitlab
spec:
storageClassName: gluster-dyn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: gitlab
labels:
app: gitlab
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: gitlab
tier: frontend
spec:
containers:
- image: gitlab/gitlab-ce:9.1.0-ce.0
name: gitlab
env:
- name: GITLAB_OMNIBUS_CONFIG
value: |
postgresql['enable'] = false
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "gitlab"
gitlab_rails['db_host'] = "postgresql"
gitlab_rails['db_port'] = "5432"
gitlab_rails['db_database'] = "gitlabhq_production"
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['db_encoding'] = 'utf8'
redis['enable'] = false
gitlab_rails['redis_host'] = 'redis'
gitlab_rails['redis_port'] = '6379'
gitlab_rails['gitlab_shell_ssh_port'] = 30022
external_url 'http://gitlab.example.com:30080'
ports:
- containerPort: 30080
name: gitlab
volumeMounts:
- name: gitlab
mountPath: /var/opt/gitlab
subPath: gitlab_data
- name: gitlab
mountPath: /etc/gitlab
subPath: gitlab_configuration
volumes:
- name: gitlab
persistentVolumeClaim:
claimName: gitlab-claim
下载的yaml部署后,postgres起不来,遇到下面的问题:
[root@localhost ~]# kubectl logs postgresql-778895955c-vqtgx
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
initdb: directory "/var/lib/postgresql/data" exists but is not empty
It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.
Using a mount point directly as the data directory is not recommended.
Create a subdirectory under the mount point.
stackoverflow已经给出了答案:
Error you get is because you want to use root folder of mounted volume `/` as postgresql Data dir
and postgresql complains that it is not best practice to do so since it is not empty and contains already some data inside
(namely `lost+found` directory).
It is far better to locate data dir in separate empty subfolder
(`/postgres` for example) and give postgresql clean slate when creating its file structure.
You didn't get same thing on minicube since you most probably mounted host folder that didn't have anything inside (was empty) and didn't trigger such a complaint.
To do so, you would need initially empty [subPath](https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath)
of your volume (empty `/postgres` subfolder on your PV for example)
mounted to appropriate mount point (`/var/lib/posgresql/data`) in your pod.
Note that you can name subPath and mount point end folder the same name,
they are different here just as an example where `test-db-volume/postgres` folder
would be mounted on pod to `/var/lib/postgresql/data` folder:
...
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: test-db-volume
subPath: postgres
...
部署后,我们再部署一个相应的ingress:
gitlab-ingress.yaml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gitlab-ingress
spec:
rules:
- host: gitlab.mine.com
http:
paths:
- backend:
serviceName: gitlab
servicePort: 80
在pc上修改hosts:
x.x.x.x gitlab.mine.com
就可以通过浏览器http://gitlab.mine.com访问了,默认用户名密码:root,root。
登录后提示修改默认密码。
待续...
网友评论