查看deployment
命令:kubectl get deploy -o wide
[root@master deploy]# kubectl get deploy -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
web1 1/1 1 1 18s nginx nginx app1=web1
[root@master deploy]#
对应关系呢如下图
查看deploy详细内容
命令:kubectl describe deployments.apps deploy_name
【deployments.apps是tab出来的内容,缩写为deploy】
[root@master http]# kubectl describe deployments.apps web1
Name: web1
Namespace: deploy
CreationTimestamp: Tue, 31 Aug 2021 16:11:25 +0800
Labels: app=web1
Annotations: deployment.kubernetes.io/revision: 1
Selector: app1=web1
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: app1=web1
app2=web2
Containers:
nginx:
Image: nginx
Port:
Host Port:
Requests:
cpu: 400m
Environment:
Mounts:
Volumes:
Conditions:
Type Status Reason
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets:
NewReplicaSet: web1-ffffb5589 (2/2 replicas created)
Events:
Type Reason Age From Message
Normal ScalingReplicaSet 10m (x2 over 20m) deployment-controller Scaled up replica set web1-ffffb5589 to 4
Normal ScalingReplicaSet 4m42s (x2 over 11m) deployment-controller Scaled down replica set web1-ffffb5589 to 3
Normal ScalingReplicaSet 4m12s deployment-controller Scaled down replica set web1-ffffb5589 to 2
[root@master http]#
yaml文件生成并解释
代码:kubectl create deploy web1 --image=nginx --dry-run=client -o yaml > web1.yaml
【代码比较基础,就不解释了,代码意思我在后面用图片表示了】
[root@master deploy]# kubectl create deploy web1 --image=nginx --dry-run=client -o yaml > web1.yaml
[root@master deploy]# cat web1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web1
name: web1
spec:
replicas: 1
selector:
matchLabels:
app: web1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web1
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
[root@master deploy]#
上面生成的呢,只是一个默认模版罢了,我们需要修改其中的某些地方,让这个文件更加合理哦。
[root@master deploy]# cat web1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web1
name: web1
spec:
replicas: 1
selector:
matchLabels:
app1: web1 #这个标签是可以自定义的,增加个1是为例和上面app有区别
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app1: web1 # 也可以定义多个标签,只要其中一个和上面的app1能对应上就行
app2: web2
spec:
terminationGracePeriodSeconds: 0 #0秒删除
containers:
- image: nginx
name: nginx
imagePullPolicy: IfNotPresent #镜像获取策略
resources: {}
status: {}
[root@master deploy]#
[root@master deploy]# kubectl apply -f web1.yaml
deployment.apps/web1 created
[root@master deploy]# kubectl get deploy -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
web1 1/1 1 1 18s nginx nginx app1=web1
[root@master deploy]#
[root@master deploy]# kubectl get pods
NAME READY STATUS RESTARTS AGE
web1-687dc7498d-bf86q 1/1 Running 0 25s
[root@master deploy]#