apiVersion: apps/v1
kind: Deployment
metadata:
name: volume-test #Deployment名称
spec:
replicas: 2 #目标副本数量
minReadySeconds: 50 # 这里需要估一个比较合理的值,从容器启动到应用正常提供服务
strategy:
rollingUpdate:
maxSurge: 1 #滚动升级时最大同时升级1个pod
maxUnavailable: 1 #滚动升级时最大允许不可用的pod个数
template:
metadata:
labels:
app: volume-test #模板名称
spec: #定义容器模板,该模板可以包含多个容器
containers:
- name: volume-test
image: 10.0.0.1:5000/volume-test:v1
args: ["--spring.profiles.active=test"] #给ENTRYPOINT命令的传参
imagePullPolicy: Always
volumeMounts: #容器内挂载点
- mountPath: /data/resources/header
name: pangu-data #必须有名称
nodeSelector: #节点选择器
type: volume-data #节点的label,将根据这个label去选择节点
volumes:
- name: volume-data #跟上面的名称对应
hostPath:
path: /data/resources/header #宿主机挂载点
selector:
matchLabels:
app: volume-test
vi rs-mongodb.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: klvchen
name: mongodb
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
nodeName: k8s-node1 # 固定在 k8s-node1 节点
containers:
- name: mongodb
image: mongo:4.2.9
resources:
limits: # 限定资源
cpu: 2000m
memory: 8Gi
requests:
cpu: 100m
memory: 8Gi
env:
- name: MONGO_INITDB_ROOT_USERNAME # 设置用户名
value: root
- name: MONGO_INITDB_ROOT_PASSWORD # 设置密码
value: 'klvchen123'
volumeMounts:
- mountPath: /data/db
name: mongodb-volume
volumes:
- name: mongodb-volume
hostPath:
path: /data/rs-mongodb-volume # 映射的宿主机目录
type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
namespace: klvchen
name: mongodb
spec:
type: ClusterIP
selector:
app: mongodb
ports:
- port: 27017
targetPort: 27017