k8s简单yml模板
一、普通部署1.1Deployment---apiVersion: apps/v1kind: Deploymentmetadata:namespace: a-envname: docker-hubspec:selector:matchLabels:app: docker-hubreplicas: 1template:metadata:labels:app: docker-hubspe.
·
一、普通部署
1.1 Deployment
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: a-env
name: docker-hub
spec:
selector:
matchLabels:
app: docker-hub
replicas: 1
template:
metadata:
labels:
app: docker-hub
spec:
# 限定为master节点
# nodeName: master
containers:
- name: docker-hub
image: registry
imagePullPolicy: IfNotPresent
ports:
- name: hubssl
containerPort: 5000
protocol: TCP
env:
- name: REGISTRY_HTTP_ADDR
value: "0.0.0.0:5000"
- name: REGISTRY_HTTP_TLS_CERTIFICATE
value: "/certs/hub.crt"
- name: REGISTRY_HTTP_TLS_KEY
value: "/certs/hub.key"
volumeMounts:
- name: data
mountPath: /var/lib/registry
- name: certs
mountPath: /certs
restartPolicy: Always
volumes:
- name: data
hostPath:
path: /a_soft/docker-hub/data
type: DirectoryOrCreate
- name: conf
hostPath:
path: /a_soft/docker-hub/conf
type: DirectoryOrCreate
- name: certs
hostPath:
path: /a_soft/ca/docker-hub
type: DirectoryOrCreate
1.2 Service
---
apiVersion: v1
kind: Service
metadata:
namespace: a-env
name: docker-hub
spec:
selector:
app: docker-hub
ports:
- name: hubssl
targetPort: hubssl
protocol: TCP
port: 5000
nodePort: 5000
type: NodePort
二、定时任务
2.1 CronJob
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
namespace: a-job
name: t3
spec:
schedule: "*/1 7 * * *" # 分 时 日 月 星期
concurrencyPolicy: Replace # 并发策略:(1)Allow(默认,并发)。(2)Forbid(保留旧的,跳过新的)。(3)Replace(跳过旧的,保留新的)。-- 附:错过的job会在启动时跟新的一起开
startingDeadlineSeconds: 7200 # 超时时间,默认永久
successfulJobsHistoryLimit: 1 # 历史成功任务显示个数
failedJobsHistoryLimit: 1 # 历史失败任务显示个数
jobTemplate:
spec:
backoffLimit: 5 # 重试最大次数
template:
# metadata: # 可以不写
# labels:
# app: test
spec:
restartPolicy: Never # 重启策略:(1)Never(2)OnFailure
containers:
- name: test
image: busybox
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
三、外部存储
3.1 PersistentVolume
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: a-soft-harbor-data
labels:
name: a-soft-harbor-data
spec:
# storageClassName:
accessModes:
- ReadWriteOnce
- ReadWriteMany
capacity:
storage: 20Gi
persistentVolumeReclaimPolicy: Retain #其他:Recycle、Delete
nfs:
server: 192.168.15.135
path: /a_soft/harbor/data
3.2 PersistentVolumeClaim
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: a-env
name: a-soft-harbor-data
spec:
# storageClassName:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
selector:
matchLabels:
name: a-soft-harbor-data
目录:https://blog.csdn.net/u013595395/article/details/114527658
更多推荐
已为社区贡献5条内容
所有评论(0)