一、创建对象
如下,创建dev命令空间
[root@master object_manage]# kubectl create namespace dev
namespace/dev created
[root@master object_manage]#
如下命令为创建一个deployment
[root@master object_manage]# kubectl create deployment nginx --image nginx -n dev
deployment.apps/nginx created
[root@master object_manage]#
二、查看对象
如下,查看dev命名空间中的pod
[root@master object_manage]# kubectl get pod -n dev
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-phb2b 1/1 Running 0 2m16s
[root@master object_manage]#
如下,查看dev命名空间中的deployment
[root@master object_manage]# kubectl get deployment -n dev
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 2m55s
[root@master object_manage]#
如下,为同时查看dev命名空间中的deployment和pod
[root@master object_manage]# kubectl get deploy,pod -n dev
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx 1/1 1 1 3m31s
NAME READY STATUS RESTARTS AGE
pod/nginx-6799fc88d8-phb2b 1/1 Running 0 3m31s
[root@master object_manage]#
三、更新对象
如下为更新deployment中的pod副本数量,由原来的1修改为3
[root@master object_manage]# kubectl scale deployment nginx -n dev --replicas 3
deployment.apps/nginx scaled
[root@master object_manage]#
此时继续查看dev命名空间下的deployment和pod,pod数量已更新为三个了
[root@master object_manage]# kubectl get deploy,pod -n dev
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx 3/3 3 3 5m40s
NAME READY STATUS RESTARTS AGE
pod/nginx-6799fc88d8-6xfbz 1/1 Running 0 18s
pod/nginx-6799fc88d8-phb2b 1/1 Running 0 5m40s
pod/nginx-6799fc88d8-sp9q8 1/1 Running 0 18s
[root@master object_manage]#
四、删除对象
如下为删除dev命名空间中的deployment
[root@master object_manage]# kubectl delete deployment nginx -n dev
deployment.apps "nginx" deleted
[root@master object_manage]#
此时查询dev命名空间的deployment和pod,发现都已经被删除了
[root@master object_manage]# kubectl get deploy,pod -n dev
No resources found in dev namespace.
[root@master object_manage]#
如下为删除dev命名空间
[root@master object_manage]# kubectl delete namespace dev
namespace "dev" deleted
[root@master object_manage]#