job
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl:5.34.0
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
completions: 1 #完成次数 默认为1
parallelism: 1 #并行数 默认为1
activeDeadlineSeconds: 30 #活跃期限 默认无限制
ttlSecondsAfterFinished: 100 #自动清理时间 默认不清理 设置单位为秒 时间到了立即清理pod
cronjob
apiVersion: batch/v1
kind: CronJob
metadata:
name: cron-get-alist
labels:
app: cron-get-alist
annotations:
app: cron-get-alist
namespace: default
spec:
schedule: "*/1 * * * *"
concurrencyPolicy: Allow #并发策略 Allow Replace
suspend: false
successfulJobsHistoryLimit: 3 #成功任务保留数
failedJobsHistoryLimit: 1 #失败任务保留数
jobTemplate:
spec:
template:
metadata:
labels: {}
annotations: {}
spec:
affinity: #容忍度
podAntiAffinity: {}
restartPolicy: OnFailure #重启策略 OnFailure Never
imagePullSecrets: [] #拉去镜像的秘钥
dnsPolicy: ClusterFirst
hostNetwork: false #主机网络
volumes:
- name: log #hostPath
hostPath:
type: ""
path: /mnt
- name: shareDir #emptyDir
emptyDir:
type: ''
- name: config #configMap
configMap:
name: test
containers:
- name: container-1
image: busybox
imagePullPolicy: IfNotPresent #镜像拉取策略
command:
- /bin/sh
- "-c"
args:
- "echo `date` >> /mnt/curl.log"
volumeMounts: #挂载数据卷
- name: log
mountPath: /mnt
subPath: "" #挂载数据卷中的子目录
env: #环境变量
- name: URL
value: "http://101.43.18.212:5244"
- name: cmURL # configMap的key
valueFrom:
configMapKeyRef:
name: test
key: url
ports: [] #暴露端口
tty: false
workingDir: "" #工作目录覆盖
resources: #资源限制
limits:
memory: 1024Mi
cpu: 1
requests:
memory: 128Mi
cpu: 100m
lifecycle: {}
initContainers: []
configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
namespace: default
data:
nginx.conf: |
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location / {
root /etc;
index hosts;
}
}
}
---
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
namespace: default
spec:
containers:
- name: nginx-container
image: nginx:latest
volumeMounts:
- name: nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-config-volume
configMap:
name: nginx-config
damonset
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
tolerations:
# 这些容忍度设置是为了让该守护进程集在控制平面节点上运行
# 如果你不希望自己的控制平面节点运行 Pod,可以删除它们
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
volumeMounts:
- name: varlog
mountPath: /var/log
# 可能需要设置较高的优先级类以确保 DaemonSet Pod 可以抢占正在运行的 Pod
# priorityClassName: important
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2 # 告知 Deployment 运行 2 个与该模板匹配的 Pod
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
StatefulSet
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None #headless svc
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx
serviceName: "nginx" #headless svc名称
replicas: 3
minReadySeconds: 10
template:
metadata:
labels:
app: nginx
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: registry.k8s.io/nginx-slim:0.24
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "my-storage-class"
resources:
requests:
storage: 1Gi
LimitRange
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-resource-constraint
spec:
limits:
- default: # 此处定义默认限制值
cpu: 500m
defaultRequest: # 此处定义默认请求值
cpu: 500m
max: # max 和 min 定义限制范围
cpu: "1"
min:
cpu: 100m
type: Container
ResourceQuota
#限制计算资源
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-resources
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi
requests.nvidia.com/gpu: 4
#限制创建对象数
apiVersion: v1
kind: ResourceQuota
metadata:
name: object-counts
spec:
hard:
configmaps: "10"
persistentvolumeclaims: "4"
pods: "4"
replicationcontrollers: "20"
secrets: "10"
services: "10"
services.loadbalancers: "2"
HorizontalPodAutoscaler
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: frontend-scaler
spec:
scaleTargetRef:
kind: ReplicaSet
name: frontend
minReplicas: 3
maxReplicas: 10
targetCPUUtilizationPercentage: 50
标签:常用,name,v1,kind,nginx,清单,k8s,spec,metadata
From: https://www.cnblogs.com/songsir/p/18527494