搭建私有仓库

编写yaml脚本
vim nginx.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 2
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: 192.168.52.10:5000/nginx
ports:
- containerPort: 80

vim nginx-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
labels:
name: nginx
spec:
type: NodePort
ports:

  • port: 80
    targetPort: 80
    nodePort: 31235
    selector:
    name: nginx

在另一台主机上
安装java环境:
解压:tar zxf jdk-8u131-linux-x64.tar.gz
移动:mv jdk1.8.0_131/ /usr/local/
修改环境变量:export JAVA_HOME=/usr/local/jdk1.8.0_131
export JRE_HOME=/usr/local/jdk1.8.0_131/jre
export CLASSPATH= J A V A H O M E / l i b / t o o l s . j a r : JAVA_HOME/lib/tools.jar: JAVAHOME/lib/tools.jar:JAVA_HOME/lib/dt.jar
export PATH= J A V A H O M E / b i n : JAVA_HOME/bin: JAVAHOME/bin:JRE_HOME/bin:$PATH
刷新:source /etc/profile
查看:java -version

安装tomcat:
解压:tar zxf apache-tomcat-7.0.54.tar.gz
移动:mv apache-tomcat-7.0.54 /usr/tomcat7
cd /usr/tomcat7/webapps/
rm -rf *
将jenkins.war放在此目录(可在jenkins官网下载)

vim /usr/tomcat7/conf/server.xml将字符集改为utf-8

安装Jenkins
修改:vim /usr/tomcat7/bin/catalina.sh
添加
export CATALINA_OPTS="-DJENKINS_HOME=/data/jenkins"
export JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dhudson.ClassicPluginStrategy.noBytecodeTransformer=true"

启动tomcat:/usr/tomcat7/bin/catalina.sh start
浏览器访问:http://192.168.52.20:8080/jenkins/
根据提示输入密码
jenkins离线,打开配置页面:http://192.168.52.20:8080/jenkins/pluginManager/advanced
升级站点(Update Site),修改URL:http://updates.jenkins.io/update-center.json
重启tomcat
推荐安装
创建用户:root

安装gitlab:
安装依赖:
yum -y install curl policycoreutils openssh-server openssh-clients postfix git
添加gitlab的repo源
curl -sS http://packages.gitlab.cc/install/gitlab-ce/script.rpm.sh | sudo bash
yum install -y gitlab-ce
修改配置文件:
vim /etc/gitlab/gitlab.rb
将external_url ‘http://gitlab.example.com’
改为external_url ‘http://192.168.52.20:90’
unicorn[‘listen’] = ‘127.0.0.1’
unicorn[‘port’] = 3000
gitlab初始化:gitlab-ctl reconfigure
浏览器访问:192.168.52.20:90
修改密码
使用root账号登录

验证:
创建密钥:ssh-keygen -t rsa
将公钥添加到gitlab ssh-key
创建项目test
git clone git@192.168.52.20:root/test.git
查看是否成功

在Jenkins安装插件:
Gitlab Authentication,GitLab,Gitlab Hook

创建新任务test,自由风格
点击源码管理,git 在URL中添加git@192.168.52.196:root/test.git
点击构建触发器,选择Build ****webhook
点击构建,选择‘执行shell’
#!/bin/bash
backupcode="/data/backcode/ J O B N A M E / JOB_NAME/ JOBNAME/BUILD_NUMBER"
mkdir -p b a c k u p c o d e c h m o d 644 " backupcode chmod 644 " backupcodechmod644"JENKINS_HOME"/workspace/“ J O B N A M E " / ∗ r s y n c − a c P " JOB_NAME"/* rsync -acP " JOBNAME"/rsyncacP"JENKINS_HOME”/workspace/"$JOB_NAME"/
b a c k u p c o d e e c h o F r o m 192.168.1.10 : 5000 / n g i n x > " backupcode echo From 192.168.1.10:5000/nginx > " backupcodeechoFrom192.168.1.10:5000/nginx>"JENKINS_HOME"/workspace/Dockerfile
echo COPY ./“ J O B N A M E " / ∗ / u s r / s h a r e / n g i n x / h t m l / > > " JOB_NAME"/* /usr/share/nginx/html/ >> " JOBNAME"//usr/share/nginx/html/>>"JENKINS_HOME”/workspace/Dockerfile
docker rmi 192.168.1.10:5000/nginx
docker build -t 192.168.1.10:5000/nginx /"$JENKINS_HOME"/workspace/.
docker push 192.168.1.10:5000/nginx
ssh root@192.168.1.10 kubectl delete deployment nginx
ssh root@192.168.1.10 kubectl apply -f /root/nginx.yaml

下载docker环境:
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce
将docker加入私有仓库

在构建触发器的url复制到gitlab
打开test项目后打开setting的Integrations,在URL项粘贴:http://192.168.52.20:8080/jenkins/project/test(直接打开setting,会进入系统设置;保证在进入项目后在点setting)
SSL verification取消
提交
进入jenkins,安装全局配置,勾中匿名用户具有可读权限,取消防止跨站点请求伪造
进入系统配置,将Enable authentication for ‘/project’ end-point 取消勾选

进入gitlab,修改全局配置,setting-network-Outbound requests,勾选‘允许发送本地请求’Allow requests to the local network from hooks and services
进入项目,settings-integrations,查看:在这里插入图片描述
测试:点击test-push events,查看返回值:
在这里插入图片描述
向master节点做免密登录:ssh-copy-id root@192.168.52.10

在jenikins查看测试结果。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐