Deployment是一个kubernetes资源对象,用于创建Pod集群,前身是RC和RS,也是现在创建无状态服务的首选对象。
一个简单的Deployment示例:
# cat deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: deploy-myapp # 标签需要一致
name: deployment-demo
spec:
replicas: 2
selector:
matchLabels:
app: deploy-myapp # 标签需要一致
template:
metadata:
labels:
app: deploy-myapp # 标签需要一致
spec:
containers:
- name: nginx-demo # pod中的容器名称,docker ps 过滤该名称能看到
image: nginx:1.20
ports:
- containerPort: 80
查看deployment
# kubectl get deployments.apps --show-labels -l app=deploy-myapp
NAME READY UP-TO-DATE AVAILABLE AGE LABELS
deployment-demo 2/2 2 2 38m app=deploy-myapp
查看deployment详情(启动有异常也通过该方法查看)
# kubectl describe deploy/deployment-demo
Name: deployment-demo
Namespace: default
CreationTimestamp: Wed, 16 Mar 2022 11:08:27 +0800
Labels: app=deploy-myapp
Annotations: deployment.kubernetes.io/revision: 2
Selector: app=deploy-myapp
Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=deploy-myapp
Containers:
nginx-demo:
Image: nginx:1.20
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: deployment-demo-5fffb97845 (2/2 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 39m deployment-controller Scaled up replica set deployment-demo-845c747588 to 2
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set deployment-demo-5fffb97845 to 1
Normal ScalingReplicaSet 12m deployment-controller Scaled down replica set deployment-demo-845c747588 to 1
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set deployment-demo-5fffb97845 to 2
Normal ScalingReplicaSet 12m deployment-controller Scaled down replica set deployment-demo-845c747588 to 0
|