k8s - Deployment
Deployment 种更高阶资源,用于音 署应用程序并 以声明的方式升级应用,而不是通过 ReplicationController Replica Set 进行部署,它们都被认为是更底层的概念
通过 deployment 创建 pod
[root@k8s-master pod]# cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80 # 容器端口
相关命令
# 创建
[root@k8s-master pod]# kubectl apply -f deployment.yaml
# 查看deployment
[root@k8s-master pod]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 14h
# 查看 replicasets
[root@k8s-master pod]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-585449566 2 2 2 14h
[root@k8s-master pod]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-deployment-585449566-7q9j7 1/1 Running 0 14h
nginx-deployment-585449566-hl4mr 1/1 Running 0 14h
[root@k8s-master pod]# kubectl describe deploy nginx-deployment
Name: nginx-deployment
Namespace: default
CreationTimestamp: Fri, 17 Dec 2021 04:32:37 +0800
Labels: app=nginx
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=nginx
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=nginx
Containers:
nginx:
Image: nginx:latest
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deployment-585449566 (2/2 replicas created)
Events: <none>