Centos7.0
准备工作
序号 | IP地址 | 主机名称 | 角色 |
---|---|---|---|
A | 192.168.100.10 | gitlab | gitlab、gitlab-runner、docker本地仓库、(K8S-Master) |
B | 192.168.100.11 | rancher | rancher、k8s节点服务器1 |
C | 192.168.100.12 | node1 | k8s节点服务器2 |
D | 192.168.100.13 | node2 | k8s节点服务器3 |
E | 192.168.100.14 | node3 | k8s节点服务器4 |
01
网络设置
以下设置需要在所有主机上设置
systemctl stop firewalld && systemctl disable firewalld
vi /etc/sysctl.conf #添加
net.ipv4.ip_forward=1
sysctl -p
hostnamectl set-hostname gitlab 针对A主机
bash
hostnamectl set-hostname rancher 针对B主机
bash
hostnamectl set-hostname node1 针对C主机
bash
hostnamectl set-hostname node2 针对D主机
bash
hostnamectl set-hostname node3 针对E主机
bash
vim /etc/hosts #添加
192.168.100.10 gitlab
192.168.100.11 rancher
192.168.100.12 node1
192.168.100.13 node2
192.168.100.14 node3
02
安装Docker
以下设置需要在所有主机上设置
yum -y remove docker docker-common container-selinux
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
cd /etc/yum.repos.d/ ls #至少保留这三个yum源
CentOS-Base.repo CentOS-Media.repo docker-ce.repo
yum clean all
yum makecache fast
yum -y install docker-ce
systemctl enable docker && systemctl start docker
docker -v
vim /etc/docker/daemon.json
{
"insecure-registries" : ["192.168.100.10:5000"]
}
systemctl restart docker
03
安装本机Docker库
在主机A(gitlab)上操作
docker run -d -p 5000:5000 --restart=always --name registry -v /mnt/registry:/var/lib/registry registry:latest
curl -XGET http://192.168.100.10:5000/v2/_catalog
04
GitLab环境安装
在主机A(gitlab)上操作
docker pull gitlab/gitlab-ce
mkdir -vp /home/huiyi/gitlab/{data,logs,config}
docker run -d -h 192.168.100.10 -p 443:443 -p 80:80 -p 1022:22 --name gitlab --restart always -v /home/huiyi/gitlab/config:/etc/gitlab -v /home/huiyi/gitlab/logs:/var/log/gitlab -v /home/huiyi/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest
05
安装GitLab Runner(两种方法)
在主机A(gitlab)上操作
方法一:
docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:latest
docker exec -it gitlab-runner bash
vi /etc/hosts
192.168.100.10 gitlab
gitlab-runner register --non-interactive --executor "docker" --docker-image "192.168.100.10:5000/ali-maven-docker:3.5.4-jdk-8-alpine" --url "http://192.168.100.10/" --registration-token " " --description "Docker runner" --tag-list "shared-runner" --run-untagged --locked="false" --docker-privileged="false"
vi /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Docker runner"
url = "http://192.168.100.10/"
token = "pXzFUNrSrwrx3552fHac"
executor = "docker"
[runners.custom_build_dir]
[runners.docker]
tls_verify = false
image = "192.168.100.10:5000/ali-maven-docker:3.5.4-jdk-8-alpine"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache", "/home/huiyi/.m2:/root/.m2"] #修改
shm_size = 0
pull_policy = "if-not-present" #添加
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
方法二:
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
yum install gitlab-runner
gitlab-runner register --non-interactive --executor "docker" --docker-image "192.168.100.10:5000/ali-maven-docker:3.5.4-jdk-8-alpine" --url "http://192.168.100.10/" --registration-token " " --description "Docker runner" --tag-list "shared-runner" --run-untagged --locked="false" --docker-privileged="false"
vi /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Docker runner"
url = "http://192.168.100.10/"
token = "pXzFUNrSrwrx3552fHac"
executor = "docker"
[runners.custom_build_dir]
[runners.docker]
tls_verify = false
image = "192.168.100.10:5000/ali-maven-docker:3.5.4-jdk-8-alpine"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache", "/home/huiyi/.m2:/root/.m2"] #修改
shm_size = 0
pull_policy = "if-not-present" #添加
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
06
安装rancher集群
在主机B(rancher)上操作
docker run -d --restart=unless-stopped -v /data:/var/lib/rancher/ -p 80:80 -p 443:443 rancher/rancher
6.1.7添加服务器主机
等待集群自动部署
主节点以及部署完成,等待worker节点
07
镜像准备
在主机A(gitlab)上操作
cd /home/
将附件一中的文件放到该用户目录下
cd ali-maven-docker/
ls
daemon.json Dockerfile settings.xml
vi daemon.json
{
"insecure-registries" : ["192.168.100.10:5000"] #修改为gitlab地址
}
docker build -t 192.168.100.10:5000/ali-maven-docker:3.5.4-jdk-8-alpine .
docker push 192.168.100.10:5000/ali-maven-docker:3.5.4-jdk-8-alpine
mkdir -pv /root/.kube/config/kubectl/
cd /root/.kube/config/kubectl/
vi Dockerfile
FROM lachlanevenson/k8s-kubectl:v1.11.0
LABEL maintainer="huiyi Name <huiyi.N@gmail.com>"
ENV KUBE_LATEST_VERSION="v1.11.0"
ADD admin.conf /root/.kube/config
WORKDIR /root
vi admin.conf
复制rancher创建的连接信息
7.2.2创建镜像,提交到私有仓库
docker build -t 192.168.100.10:5000/kubectl:1.11.0 .
docker push 192.168.100.10:5000/kubectl:1.11.0
docker pull fancybing/java:serverjre-8
08
创建GitLab项目
8.1.2创建项目
Key: DOCKER_HUB_REPO Value:192.168.100.10:5000/k8s-ci