【openshift】在Openshift上通过yaml部署应用
在Openshift上通过yaml部署应用
1.通过直接执行yaml
通过如下命令直接执行
oc create -f nginx.yml
nginx.yml
apiVersion: v1
items:
- apiVersion: apps.openshift.io/v1
# okd 部署配置(dc),与 k8s Deployment 资源对象类似,以启动多个容器的方式生成 pod
kind: DeploymentConfig
metadata:
# 标签,在查询时具体资源对象时非常重要,如:>oc get dc -l app=nginx
labels:
app: nginx
name: nginx
# 选定项目空间
namespace: test
spec:
# 副本数,即 nginx app 部署的实例数
replicas: 1
# pod 的计算资源配额
resources:
# pod 能分配的最大计算资源
limits:
cpu: 300m
memory: 1024Mi
# pod 分配的最少计算资源
requests:
cpu: 100m
memory: 200Mi
# 选择器 Service 根据此项来绑定到 dc
selector:
name: nginx
strategy:
# type: Recreate
type: Rolling
# dc 根据模板里内容创建 pod
template:
metadata:
labels:
app: nginx
name: nginx
deploymentconfig: nginx
spec:
# 容器集合
containers:
- capabilities: {}
# 容器内环境变量,下文给这个容器设置了时区和语言的环境变量
env:
- name: TZ
value: Asia/Shanghai
- name: LANG
value: en_US.UTF-8
# 容器使用什么镜像部署,在创建时需要替换成实际要部署的镜像
image: nginx:1.16
# 镜像下载策略,总是下载最新的(Always)
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
protocol: TCP
# 健康检查-pod 是否存活
livenessProbe:
failureThreshold: 2
# http get 请求的方式验证 pod-ip:80/
httpGet:
path: /
port: 80
initialDelaySeconds: 60
periodSeconds: 60
timeoutSeconds: 5
name: nginx
# 健康检查-pod 是否就绪
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
timeoutSeconds: 5
# 容器计算资源配额,与 pod 配额类似
resources:
limits:
cpu: 300m
memory: 1024Mi
requests:
cpu: 100m
memory: 200Mi
securityContext:
capabilities: {}
# privileged: true
terminationMessagePath: /dev/termination-log
# 将 pod 中配置的卷挂载到容器内
# volumeMounts:
# - mountPath: /data
# name: nginx
dnsPolicy: ClusterFirst
# 使用节点选择器将应用固定部署到 node1 计算节点上
# nodeSelector:
# kubernetes.io/hostname: node1.app.com
restartPolicy: Always
# 配置和定义使用实际计算节点主机文件夹地址这种类型的卷
# volumes:
# - persistentVolumeClaim:
# claimName: nginx
# name: nginx
# pod 触发器--配置变动触发更新
triggers:
- type: ConfigChange
- apiVersion: v1
# 服务,与 k8s 中 service 一样,将 dc 上部署的应用暴露给内部(多)或外部(少)
kind: Service
metadata:
labels:
app: nginx
name: nginx
spec:
# 应用中要暴露的端口信息
ports:
- name: http
# 对外暴露的端口
port: 80
protocol: TCP
# 应用实际端口
targetPort: 80
# 通过选择器选择 dc
selector:
name: nginx
sessionAffinity: None
type: ClusterIP
- apiVersion: route.openshift.io/v1
# OKD 平台特有资源,与 k8s 中 ingress 类似,用于将 service 正真暴露给外部使用,但只能使用域名访问
kind: Route
metadata:
labels:
app: nginx
name: nginx
spec:
# 配置域名
host: xinchen.app.com
to:
kind: Service
name: nginx
kind: List
metadata: {}
2. 通过创建template
参考文档: https://docs.okd.io/latest/dev_guide/templates.html#writing-templates
相关指令
# 上传模板
oc create -f <filename> -n <project>
# 使用模板
oc process -f nginx-template -p IMAGE_NAME=nginx:1.6 -p REPLICA_COUNT=1
# 编辑模板
oc edit template <templateName>
# 导出模板
oc get -o yaml --export all > <yaml_filename>
nginx-template.yml
kind: Template
apiVersion: v1
metadata:
name: nginx-template
objects:
- kind: DeploymentConfig
apiVersion: v1
metadata:
name: nginx
namespace: xinchen
labels:
app: nginx
spec:
replicas: ${REPLICA_COUNT}
selector:
name: nginx
resources:
limits:
cpu: 300m
memory: 1024Mi
requests:
cpu: 100m
memory: 200Mi
strategy:
type: Rolling
template:
metadata:
labels:
app: nginx
name: nginx
deploymentconfig: nginx
spec:
containers:
- capabilities: {}
env:
- name: TZ
value: Asia/Shanghai
- name: LANG
value: en_US.UTF-8
image: ${IMAGE_NAME}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
protocol: TCP
livenessProbe:
failureThreshold: 2
httpGet:
path: /
port: 80
initialDelaySeconds: 60
periodSeconds: 60
timeoutSeconds: 5
name: nginx
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
timeoutSeconds: 5
resources:
limits:
cpu: 300m
memory: 1024Mi
requests:
cpu: 100m
memory: 200Mi
securityContext:
capabilities: {}
# privileged: true
terminationMessagePath: /dev/termination-log
# volumeMounts:
# - mountPath: /data
# name: nginx
dnsPolicy: ClusterFirst
restartPolicy: Always
# volumes:
# - persistentVolumeClaim:
# claimName: nginx
# name: nginx
# pod 触发器--配置变动触发更新
triggers:
- type: ConfigChange
- kind: Service
apiVersion: v1
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- name: 80-tcp
port : 80
protocol: TCP
targetPort: 80
selector:
name: nginx
sessionAffinity: None
type: ClusterIP
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: nginx
name: nginx
spec:
host: ${HOST_NAME}
port:
targetPort: 80-tcp
to:
kind: Service
name: nginx
weight: 100
parameters:
- name: HOST_NAME
displayName: Host Name
required: true
- name: IMAGE_NAME
displayName: Image Name
required: true
- name: REPLICA_COUNT
displayName: Replica Count
value: "1"
required: true
3. 进入运行的容器
参考: https://docs.okd.io/latest/dev_guide/ssh_environment.html
# 查看pod名
oc get pods
# 进入容器
oc rsh <pod>
# 或者直接进入dc
oc rsh dc/nginx
4. 删除所有
# 删除所有
oc delete all -l app=nginx
【openshift】在Openshift上通过yaml部署应用的更多相关文章
- java免费空间!最简单的openshift免费空间上传代码教程!和FTP一样简单!
史上最简单的openshift免费空间上传代码教程!没有之一! 最近因为想弄一个免费的空间,而且最好是Java的空间,找了一大片,jsp的空间少不说,免费的更是寥寥无几. 找了一大推垃圾空间,终于让我 ...
- Ubuntu上通过nginx部署Django笔记
Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式.今天在Ubuntu上使用Nginx部署Django服务,虽然不是第一次搞这个了,但是发现还是跳进了好多坑,g ...
- flask在windows上用mod_wsgi部署
flask在windows上用mod_wsgi部署也是折腾了不少时间,下面就总结下. 首先下载Apache httpd,我认为Apache Hans比较好: 一般这种情况下,你的python环境已经安 ...
- 如何在Azure上创建和部署云服务
Azure 管理门户提供两种方法可用来创建和部署一个云服务:快速创建和自定义创建. 本主题说明如何使用快速创建方法来创建新的云服务,然后使用上传来上载和部署一套在 Azure 的云服务.当您使用此方法 ...
- Ubuntu 14.04 上使用 Nginx 部署 Laravel
本教程将会涉及以下工具: Ubuntu 14.04 LTS PHP 5.5 MySQL Laravel 5.0 Nginx 参考文章:Ubuntu 14.04 上使用 Nginx 部署 Laravel ...
- Jenkins-在windows上配置自动化部署(Jenkins+Gitblit)
Jenkins-在windows上配置自动化部署(Jenkins+Gitblit) 1. 安装好 Jenkins(注:安装目录需没有空格,否则安装gitlab hook 插件时会报错,安装在c盘跟目录 ...
- 【转载】在Centos系统上采用二进制文件部署Node.js环境
Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,用来方便地搭建快速的易于扩展的网络应用.Node.js 使用了一个事件驱动.非阻塞式 I/O 的模型,使其轻量又 ...
- Redis在CentOS 7上的安装部署
简介: Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支持在服务器端计算集合的并,交和补集( ...
- 通过上一节部署出来的 Windows instance 有时候会发现操作系统时间总是慢 8 个小时,即使手工调整好时间和时区,下次 instance 重启后又会差 8 个小时
这是 OpenStack 实施经验分享系列的第 3 篇. 问题描述 通过上一节部署出来的 Windows instance 有时候会发现操作系统时间总是慢 8 个小时,即使手工调整好时间和时区,下次 ...
随机推荐
- java spring学习
目的:为后面学习spring mvc ssm spring boot 打基础. 从单词就能看到有s,记录自学过程,感慨spring 一篇文章都写不完 介绍(来源百度百科): Spring是一个开源框架 ...
- 作业:分布式文件系统HDFS 练习
这个作业的要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3292. 利用Shell命令与HDFS进行交互 1.目录操作 H ...
- Java_jdbc 基础笔记之十五 数据库连接(取得数据库自动生成的主键)
public class testGetKeyValue { /** * 取得数据库自动生成的主键 */ @Test public void testGeneratedKeys() { Connect ...
- Nginx可以做什么?(转载)
本文只针对Nginx在不加载第三方模块的情况能处理哪些事情,由于第三方模块太多所以也介绍不完,当然本文本身也可能介绍的不完整,毕竟只是我个人使用过和了解到过得,欢迎留言交流. Nginx能做什么 —— ...
- Comparator中返回0导致数据丢失的大坑
今天对一列数据进行排序,因为存储的是Map结构,要实现排序,马上就想到了TreeMap,于是查到API,这样新建TreeMap就能实现添加的时候就自动排序. new TreeMap<>(n ...
- 支付宝即时到账交易接口C#接入方式的几个坑
1.在官方文档中 https://docs.open.alipay.com/62/104743 可以清楚看到input_charset前面没有要求加下横杠,可是请求示例是带着的.经过实验得知,这个必须 ...
- 008 webpack的其他使用方式
一:配置 1.配置文件 每次修改main文件,重新打包都要指定入口与出口,比较费事,可以使用配置文件的方式 在根目录下新建webpack.config.js: const path = require ...
- understand-show-slave-status-g
https://dba.stackexchange.com/questions/22623/mysql-exec-master-log-pos-value-greater-than-read-mast ...
- 【docker】 yaml.scanner.ScannerError: mapping values are not allowed here in "./docker-compose.yml", line 60, column 35
在启动docker-compose 时候 报错了 命令: docker-compose up -d && docker-compose logs -f 错误代码: 解决 出现这个错误的 ...
- jsp 记录
前后端开发好久后,一直没怎么用前端开发了.最近任务比较急,又开始写jsp页面了... 1)jquery.validate.min.js 用法总结 https://www.cnblogs.com/x ...