编写OpenShift的yaml以定义容器
一、创建secret
在OpenShift左侧Resources->Secret->Create Secret里选择Image Secret后创建。
二、编写yaml
1. ConfigMap
apiVersion: V1
kind: ConfigMap
metadata:
name: app-config-map
data:
application.properties: |
spring.profiles.active=dev
server.xml: >-
<?xml version='1.0' encoding='utf-8'?>
2. Deployment
apiVersion: V1
kind: Deployment
metadata:
name: app
spec:
#定义副本数量
replicas: 2
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
spec:
imagePullSecrets:
- name: ${secret_name}
containers:
- name: app
image: ${artifactory_url}/${dev_project_name}/${app_name}:'BUILD_ID'
imagePullPolicy: Always
#设置资源配额
resources:
limits:
cpu: 2000m
memory: 4Gi
env:
- name: TZ
value: Asia/Shanghai
ports:
- containerPort: 8080
#挂载到容器目录
volumeMounts:
- mountPath: /opt/tomcat/conf/server.xml
name: [volume-app]
readOnly: true
subPath: server.xml
#定义容器就绪探针
readinessProbe:
tcpSocket:
port: 8080
periodSeconds: 10
#定义容器探活探针
livenessProbe:
periodSeconds: 5
httpGet:
path: /health
port: 8080
volumes:
- configMap:
defalutMode: 420
#对应1.ConfigMap的名称
name: app-config-map
name: [volume-app]
3. Service
apiVersion: V1
kind: Service
metadata:
name: app
spec:
ports:
- port: 8080
targetPort: 8080
name: app
selector:
app: app
4. Route
apiVersion: V1
kind: Route
metadata:
name: app
spec:
host: app.test.com
#path: /test
to:
kind: Service
#对应3.Service
name: app
weight: 100
wildcardPolicy: None
三、应用yaml
在OpenShift右侧Add to Project->Import YAML/JSON里导入上述4个yaml文件。