openshift 容器云从入门到崩溃之六《Source-to-Image》
上次说到了怎么在oc上面部署应用而且说道了怎么定义模板部署应用,也许你会奇怪那个我代码打包编译在哪一步,那就要说道oc的s2i流程了
下面是基本s2i流程

1、制作base-image镜像
要使用s2i流程首先需要打好包含s2i程序的镜像
准备s2i脚本
1、下载s2i程序
https://github.com/openshift/source-to-image/releases/
2、生成s2i脚本
# s2i create openresty s2i-openresty
# cd s2i-openresty
# ls
# cd s2i/bin
# ls


assemble 复杂编译打包应用是在Build的时候执行的
run 负责启动应用是在deployment之后容器的来的时候执行的
下面是一个nginx镜像的例子:
PS:这里我应的ubuntu镜像强烈建议使用oc提供的openshift/base-centos7 不然你会遇到很多SCC的问题
# cat Dockerfile
FROM ubuntu:16.04
MAINTAINER sen.zhang@downtown8.com LABEL \
io.openshift.s2i.scripts-url=image:///usr/libexec/s2i ENV \
STI_SCRIPTS_PATH=/usr/libexec/s2i COPY ./sources.list /etc/apt/ RUN set -x \
&& apt-get -y update \
&& apt-get -y install libpcre3-dev libssl-dev perl make build-essential curl \
sudo vim telnet net-tools iputils-ping psmisc git wget COPY ./src/ /usr/local/src/ RUN set -x \
&& cd /usr/local/src/sregex \
&& make -j4 \
&& make install \
&& cd /usr/local/src/openresty \
&& ./configure \
--prefix=/data/app/openresty \
--error-log-path=/data/logs/nginx/error.log \
--http-log-path=/data/logs/nginx/access.log \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-stream=dynamic \
--with-openssl=/usr/local/src/openssl \
--add-dynamic-module=/usr/local/src/nchan \
--add-module=/usr/local/src/replace-filter-nginx-module \
&& make -j4 \
&& make install \
&& rm -rf usr/local/src/* RUN set -x \
&& mkdir -p /data/disk-mem /data/disk-cache /data/logs/nginx \
&& ln -s /data/app/openresty/nginx/sbin/* /sbin/ \
&& ln -sf /bin/bash /bin/sh \
&& ln -sf /usr/local/lib/libsregex.so.0 /lib/libsregex.so.0 \
&& /data/app/openresty/nginx/sbin/nginx -V \
&& useradd www -u 1001 \
&& echo "www ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& chown -R www.www /data COPY ./s2i/bin/ /usr/libexec/s2i USER 1001
EXPOSE 80 8080
CMD ["/usr/libexec/s2i/usage"]
强烈建议assemble具体逻辑放到网络脚本当中不然会经常要改base镜像
# cat assemble
#!/bin/bash -e #执行自定义动作
curl http://build.xxx.cn/build/nginx/nginx_s2i_build.sh |sh
run脚本就可以写死了
#!/bin/bash -e
echo "开始运行...." #处理dns
nginx_conf="/data/app/openresty/nginx/conf/nginx.conf"
nameserver=`cat /etc/resolv.conf |grep nameserver |head -n |awk '{print $2}'`
echo "resolver=$nameserver"
sed -i s/223.5.5.5/$nameserver/g $nginx_conf #启动nginx
echo 'sudo nginx -g "daemon off;"'
sudo nginx -g "daemon off;"
2、上传镜像到docker-registry
oc安装的时候默认在default项目会默认安装一个docker-registry,作用是保存base-image、build-image
刚才制作的base-image就可以上传到docker 仓库当中了
# docker build -t="registry.oc.example.com/openshift/nginx:latest
# docker login -u"default/api-admin" -p"$token" registry.oc.example.com
# docker push registry.oc.example.com/openshift/nginx:latest
还记得上节那个自定义模板中的${APP_BUILDER_IMAGE}变量应该填写nginx:latest
openshift 容器云从入门到崩溃之六《Source-to-Image》的更多相关文章
- openshift 容器云从入门到崩溃之八《日志聚合》
日志可以分为两部分 业务日志 业务日志一般是要长期保留的,以供以后有问题随时查询,elk是现在比较流行的日志方案,但是容器日志最好不要落地所以不能把logstash客户端包在容器里面 可以使用logs ...
- openshift 容器云从入门到崩溃之五《部署应用》
1.配置部署模板 配置好用户权限之后就可以部署应用了oc常用的两种部署方式: Deploy Image方式 优点:这种方式是最简单的部署方式,你只需要有一个容器镜像就行了或者公开的docker hub ...
- openshift 容器云从入门到崩溃之二《准备环境》
openshift 从3.9开始就开始支持系统组件在容器里运行了,之前版本都是直接运行在操作系统上,名字也改了叫OKD 目前最新的稳定版本是3.11,所以就安装3.11版本 准备环境: 主机名 系统 ...
- openshift 容器云从入门到崩溃之一《容器能解决什么问题》
容器前时代 说到容器大多数人想到的就是docker,docker的迅速崛起使得使用容器的门槛大大降低了,我第一次接触docker还是14年,那时候作为一名运维部署应用还在大量使用虚拟化,从vmware ...
- openshift 容器云从入门到崩溃之九《容器监控-报警》
容器状态监控 主要是监控POD的状态包括重启.不健康等等这些k8s api 状态本身会报出来,在配合zabbix报警 导入zabbix模板关联上oc master主机 <?xml version ...
- openshift 容器云从入门到崩溃之七《数据持久化》
数据持久化常用的有两种: hostPath 挂载容器宿主机的本地文件夹,直接修改pod的配置 volumes: - hostPath: path: /data/logging-es type: '' ...
- openshift 容器云从入门到崩溃之三《安装openshift》
准备好环境,在安装之前请先了解openshift提供的ansible有大量的安装选项 文档地址:https://docs.okd.io/latest/install/configuring_inven ...
- openshift 容器云从入门到崩溃之十《容器监控-数据展示》
POD资源历史曲线(CPU.内存.网络) 监控方案heapster+hawkular-metrics+hawkular-cassandra heapster负责收集数据 hawkular-cassan ...
- openshift 容器云从入门到崩溃之四《配置用户验证》
1.配置本地用户 之前安装的时候选择了htpasswd验证方式 先创建用户 # htpasswd -c /etc/origin/master/htpasswd admin 授权为集群管理员 # oc ...
随机推荐
- mongodb应用
一.概述 NoSQL,指的是非关系型的数据库.NoSQL有时也称作Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统的统称.NoSQL用于超大规模数据的存储.(例如谷歌或Fa ...
- VMware Workstation 14.1.1 精简特别版
VMware Workstation 精简特别版,由卡饭网友のcuiplay精简制作,集成许可证密钥安装即永久激活,该特别版最大特色可安装MAC OS X客户操作系统,此外添加了DELL SLIC 2 ...
- Laravel 执行流程(一)之自动加载
定位 从 public/index.php 定位到 bootstrap/autoload.php 从 bootstrap/autoload.php 定位到 vendor/autoload.php 从 ...
- Unity长连接
http://blog.csdn.net/claine/article/details/52374546
- MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report e
早上来到公司,线上的项目报错: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionExcepti ...
- k8s(4)-使用服务公开应用程序
Kubernetes中的服务是一个抽象,它定义了一组逻辑Pod和一个访问它们的策略.服务允许从属Pod之间的松散耦合.与所有Kubernetes对象一样,使用YAML (首选)或JSON 定义服务.服 ...
- selenium+chromedriver刷点击量
#coding=utf-8 import re import time import json import requests from selenium import webdriver from ...
- mac 互传文件
搭建HTTP服务,然后局域网访问就行 PHP方式: php -S 172.21.205.xxx:9999 Python python -m SimpleHTTPServer 8001 在浏览器访问:h ...
- windows安装mysql8
1:首先去官网下载安装包 下载地址:https://dev.mysql.com/downloads/mysql/ 2:将解压文件解压到你安装的目录:E:\mysql-8.0.11-winx64 (我 ...
- Java课程寒假之开发记账本软件(网页版)之五
一.实现基本功能之后 可以添加其他功能,比如说添加账户,删除账户,以及查询页面的分页.(我都没写,滑稽) 二.基本功能部分截图