mysql-pod.yaml
# overView:
# 1. web服务与db打包放在同一个pod中,本地通过localhost来访问,并附带存活性/可用性检测
# 2. 补充重启策略/镜像拉去策略
# 3. 对容器资源进行限制
apiVersion: apps/v1
kind: Pod
metadata:
name: pub-oa
namespace: hunter
labels:
component: pub-oa
spec:
restartPolicy: onFailure # 设置重启策略,此外还有 Always, Never方式
volumes:
- name: mysql
hostPath:
path: /opt/mysql/data
nodeSelector:
component: prod-k8s-node1 # kubectl label node prod-k8s-node1 component=prod-k8s-node1
containers:
- name: pub-oa-db
image: rigistry.cn-shanghai.aliyuncs.com/pub-oa-db:v1
imagePullPolicy: IfNotPresent # 镜像拉去策略,此外还有Always, Never
ports:
- containerPort: 3306
env:
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: pub-oa
key: MYSQL_USER
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: pub-oa
key: MYSQL_PASSWORD
resources: # 容器资源限制
requests:
memory: 100Mi # 当pod内存超过100Mi时,会报OOM
cpu: 50m # 当cpu超过limit限制时,不会被kill,但是会限制不超过limit值,1 CPU = 1000 millicpu(1 core = 1000m(毫核)),cpu资源是按 “时间片”的方式来分配的
limits:
memory: 500Mi
cpu: 100m
volumeMounts:
- name: mysql
mountPath: /var/lib/mysql
web-pod.yaml
# overView:
# 1. web服务与db打包放在同一个pod中,本地通过localhost来访问,并附带存活性/可用性检测
# 2. 补充重启策略/镜像拉去策略
# 3. 对容器资源进行限制
apiVersion: apps/v1
kind: Pod
metadata:
name: pub-oa
namespace: hunter
labels:
component: pub-oa
spec:
restartPolicy: onFailure # 设置重启策略,此外还有 Always, Never方式
nodeSelector:
component: prod-k8s-node1 # kubectl label node prod-k8s-node1 component=prod-k8s-node1
containers:
- name: pub-oa-web
image: rigistry.cn-shanghai.aliyuncs.com/pub-oa-app:v1
imagePullPolicy: IfNotPresent # 镜像拉去策略,此外还有Always, Never
ports:
- containerPort: 8080
env:
- name: MYSQL_HOST
valueFrom:
secretKeyRef:
name: pub-oa
key: MYSQL_HOST
- name: MYSQL_PORT
valueFrom:
secretKeyRef:
name: pub-oa
key: MYSQL_PORT
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: pub-oa
key: MYSQL_USER
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: pub-oa
key: MYSQL_PASSWORD
livenessProbe: # 存活性探测
httpGet: # 此外还有 exec,tcpSocket类型
path: /code-library/listCodeLibrary
port: 8080
scheme: HTTP
initialDelaySeconds: 10 # 容器启动后,第一次执行探测时需要等待多少秒
periodSeconds: 10 # 执行探测的频率
timeoutSeconds: 2 # 探测超时时间
readinessProbe: # 可用性探测
httpGet: # 此外还有 exec,tcpSocket类型
path: /code-library/listCodeLibrary
port: 8080
scheme: HTTP
initialDelaySeconds: 10 # 容器启动后,第一次执行探测时需要等待多少秒
periodSeconds: 10 # 执行探测的频率
timeoutSeconds: 2 # 探测超时时间
resources: # 容器资源限制
requests:
memory: 100Mi # 当pod内存超过100Mi时,会报OOM
cpu: 50m # 当cpu超过limit限制时,不会被kill,但是会限制不超过limit值,1 CPU = 1000 millicpu(1 core = 1000m(毫核)),cpu资源是按 “时间片”的方式来分配的
limits:
memory: 500Mi
cpu: 100m
volumeMounts:
- name: mysql
mountPath: /var/lib/mysql
configMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: pub-oa
namespace: hunter
data:
MYSQL_HOST: 192.168.179.141
MYSQL_PORT: 3306
sceret.yaml
apiVersion: v1
kind: Secret
metadata:
name: pub-oa
namespace: hunter
type: Opaque
data:
MYSQL_USER: cm9vdA== # 注意加-n参数,echo -n root|base64
MYSQL_PASSWORD: aHVudGVy
文章来源地址https://www.toymoban.com/news/detail-700197.html
文章来源:https://www.toymoban.com/news/detail-700197.html
到了这里,关于K8S之使用yaml格式定义pod的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!