k8s kubernetes给node节点添加标签和删除node节点标签
Deployment配置文件exampledeploymentv1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
template:
metadata:
labels:
app: nginx
track: stable
spec:
restartPolicy: Always
nodeSelector:
mem: large
volumes:
- name: nginx-logs
emptyDir: {}
containers:
- name: nginx
image: nginx:1.7.9
imagePullPolicy: Always
ports:
- containerPort: 80
hostPort: 8080
protocol: TCP
volumeMounts:
- name: nginx-logs
mountPath: /var/log/nginx/
livenessProbe:
httpGet:
port: 80
path: /check_healty
host: ping.zhufunin.com
scheme: HTTP
httpHeaders:
- name: user-agent
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
创建Deployment控制器
kubectl apply -f exampledeploymentv1.yaml --record
这里一定要加--record, 每次修改Deployment控制器时所使用的命令都会记录到备注字段,
以便在查看Deployment控制器变更历史或者回滚时可以辨别每次修改的内容
DaemonSet配置文件
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: daemon-httpd
spec:
selector:
matchLabels:
name: daemon-httpd
template:
metadata:
labels:
name: daemon-httpd
spec:
containers:
- name: daemon-httpd
image: httpd
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
hostPort: 8088
protocol: TCP
Job配置文件
开启ttlSecondsAfterFinished,给job结束后设置自动删除时间
这个功能默认是没有开启的,需要手动修改/etc/kubernetes/manifests下面的三个yaml文件
kube-apiserver.yaml kube-controller-manager.yaml kube-scheduler.yaml
加入 - --feature-gates=TTLAfterFinished=true
activeDeadlineSeconds
是指超时的时间
apiVersion: batch/v1
kind: Job
metadata:
name: job-test
spec:
ttlSecondsAfterFinished: 30
completions: 11
parallelism: 3
# activeDeadlineSeconds: 30
template:
spec:
restartPolicy: Never
containers:
- name: job-test
image: busybox
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c' ]
args: [ 'echo "start jobs";sleep 30;echo "jobs done!"']
CronJob配置文件
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: echo-cronjob
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
containers:
- name: echo-cronjob
image: busybox
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c' ]
args: [ 'echo "start cronjob!";sleep 30;echo "end cronjob!"' ]
未完工,待续