常见Pod控制器:
控制器名称 | 作用 |
---|---|
Deployment | 声明式更新控制器,用于发布无状态应用 |
ReplicaSet | 副本集控制器,用于对Pod进行副本规模扩大或剪裁 |
StatefulSet | 有状态副本集,用于发布有状态应用 |
DaemonSet | 在k8s集群每一个Node上运行一个副本,用于发布监控或日志收集类等应用 |
Job | 运行一次性作业任务 |
CronJob | 运行周期性作业任务 |
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-apps
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginxapp
image: nginx:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 88
resources:
limits:
cpu: '1'
memory: 1Gi
requests:
cpu: 200m
memory: 512Mi
root@k8s1:/home# kubectl apply -f 03-create-deployment-app.yaml
deployment.apps/nginx-apps created
查看Deployment控制器类型应用
root@k8s1:/home# kubectl get deployments.apps
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-apps 1/1 1 1 107s
查看ReplicaSet控制器类型应用
root@k8s1:/home# kubectl get replicaset.apps
NAME DESIRED CURRENT READY AGE
nginx-apps-6c44bdcdc7 1 1 1 2m48s
查看Pod状态
root@k8s1:/home# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-apps-6c44bdcdc7-8bwt7 1/1 Running 0 3m40s
带有控制器类型的Pod不能随便删除,如果必须删除,请删除控制器类型的应用名称。
root@k8s1:/home# kubectl get deployment.apps
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-apps 1/1 1 1 6m58s
root@k8s1:/home# kubectl delete deployments.apps nginx-apps
deployment.apps "nginx-apps" deleted
root@k8s1:/home# kubectl get deployment.apps
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-apps 1/1 1 1 6m58s
root@k8s1:/home# kubectl delete -f 03-create-deployment-app.yaml
deployment.apps "nginx-apps" deleted
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_43296313/article/details/121335766
内容来源于网络,如有侵权,请联系作者删除!