在K8S v1.18.0以后,–replicas已弃用,并且只创建一个nginx 容器实例
[root@master1 yamldir]# kubectl run nginx-app1 --image=nginx:latest --image-pull-policy=IfNotPresent --replicas=2
Flag --replicas has been deprecated, has no effect and will be removed in the future.
pod/nginx-app1 created
[root@master1 yamldir]# kubectl get deployment
No resources found in default namespace.
[root@master1 yamldir]# kubectl get deployment.apps
No resources found in default namespace.
[root@master1 yamldir]# cat 03_create_deployment_nginx_app2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-app2
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginxapp2-container
image: nginx:latest
imagePullPolicy: IfNotPresent
ports:
- name: nginxapp2
containerPort: 80
[root@master1 yamldir]# kubectl apply -f 03_create_deployment_nginx_app2.yaml
deployment.apps/nginx-app2 created
[root@master1 yamldir]# kubectl get deployment.apps
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-app2 1/1 1 1 38s
[root@master1 yamldir]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-app2-7b78bfb8c8 1 1 1 58s
[root@master1 yamldir]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-app1 1/1 Running 0 128m
nginx-app2-7b78bfb8c8-jnssc 1/1 Running 0 74s
[root@master1 yamldir]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-app1 1/1 Running 0 128m 172.16.189.67 worker2 <none> <none>
nginx-app2-7b78bfb8c8-jnssc 1/1 Running 0 97s 172.16.235.129 worker1 <none> <none>
[root@master1 yamldir]# curl http://172.16.235.129
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@master1 yamldir]#
删除
[root@master1 yamldir]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-app1 1/1 Running 0 132m
nginx-app2-7b78bfb8c8-jnssc 1/1 Running 0 5m43s
[root@master1 yamldir]# kubectl delete pods nginx-app1 -n default
pod "nginx-app1" deleted
You have new mail in /var/spool/mail/root
[root@master1 yamldir]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-app2-7b78bfb8c8-jnssc 1/1 Running 0 7m51s
[root@master1 yamldir]# kubectl delete pods nginx-app2-7b78bfb8c8-jnssc -n default
pod "nginx-app2-7b78bfb8c8-jnssc" deleted
[root@master1 yamldir]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-app2-7b78bfb8c8-dwk78 0/1 ContainerCreating 0 19s
[root@master1 yamldir]#
没有真实删除
[root@master1 yamldir]# kubectl get deployment.apps
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-app2 1/1 1 1 10m
[root@master1 yamldir]# kubectl delete deployment.apps nginx-app2
deployment.apps "nginx-app2" deleted
[root@master1 yamldir]# kubectl get rs
No resources found in default namespace.
[root@master1 yamldir]# kubectl get pods
No resources found in default namespace.
[root@master1 yamldir]#
使用资源清单文件删除
[root@master1 yamldir]# kubectl apply -f 03_create_deployment_nginx_app2.yaml
deployment.apps/nginx-app2 created
[root@master1 yamldir]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-app2-7b78bfb8c8 1 1 0 22s
[root@master1 yamldir]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-app2-7b78bfb8c8-7pj65 0/1 ContainerCreating 0 28s
[root@master1 yamldir]# kubectl delete -f 03_create_deployment_nginx_app2.yaml
deployment.apps "nginx-app2" deleted
[root@master1 yamldir]# kubectl get rs
No resources found in default namespace.
[root@master1 yamldir]# kubectl get pods
No resources found in default namespace.
[root@master1 yamldir]#