K8S核心资产管理方法

陈述式资管管理

管理名称空间资源

查看名称空间

$ kubectl get namespace
NAME              STATUS   AGE
default           Active   45d
kube-node-lease   Active   45d
kube-public       Active   45d
kube-system       Active   45d

$  kubectl get ns		//namespace == ns
NAME              STATUS   AGE
default           Active   45d
kube-node-lease   Active   45d
kube-public       Active   45d
kube-system       Active   45d

查看名称空间内部资源

$ kubectl get all  -n default

// pod资源
NAME                 READY   STATUS    RESTARTS   AGE
pod/nginx-ds-4l68x   1/1     Running   2          45d
pod/nginx-ds-6sxqd   1/1     Running   1          44d

//service资源
NAME                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   192.168.0.1   <none>        443/TCP   45d

//pod控制器
NAME                      DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/nginx-ds   2         2         2       2            2           <none>          45d

查看名称空间

$ kubectl create namespace app
namespace/app created
$ kubectl get ns |grep app
app               Active   14s

删除名称空间

$ kubectl delete namespace app
namespace "app" deleted

管理Deployment资源

创建Deployment资源

$ kubectl create  deployment nginx-dp  --image=harbor.od.com/public/nginx:v1.7.9 -n kube-public

deployment.apps/nginx-dp creat
//--image 指定镜像下载

查看Deployment资源

// 简单查看
$ kubectl get deployment -n kube-public
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
nginx-dp   1/1     1            1           76s

// 扩展查看
$ kubectl get pods -n kube-public
NAME                        READY   STATUS    RESTARTS   AGE
nginx-dp-5dfc689474-ss7cr   1/1     Running   0          2m18s

查看Deployment详情

$ kubectl describe deployment nginx-dp -n kube-public
Name:                   nginx-dp
Namespace:              kube-public
CreationTimestamp:      Thu, 14 May 2020 11:19:50 +0800
Labels:                 app=nginx-dp
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx-dp
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate	//更新策略,默认滚动发布
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge	
Pod Template:
  Labels:  app=nginx-dp
  Containers:
   nginx:
    Image:        harbor.od.com/public/nginx:v1.7.9
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-dp-5dfc689474 (1/1 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  3m40s  deployment-controller  Scaled up replica set nginx-dp-5dfc689474 to 1

查看pod资源

$  kubectl get pods -n kube-public -o wide
NAME                        READY   STATUS    RESTARTS   AGE   IP           NODE                NOMINATED NODE   READINESS GATES
nginx-dp-5dfc689474-wnhlh   1/1     Running   0          79s   172.7.21.4   zzgw7-21.host.com   <none>           <none>

进入pod资源

也是可以使用docker exec方式,但必须是pod运行的节点上。

$ kubectl exec -ti nginx-dp-5dfc689474-wnhlh /bin/bash -n kube-public
root@nginx-dp-5dfc689474-wnhlh:/# 

删除pod资源(重启)

$ kubectl delete pod nginx-dp-5dfc689474-wnhlh -n kube-public 
pod "nginx-dp-5dfc689474-wnhlh" deleted

强制删除参数:–force --grace-period=0

执行delete删除后,会马上重建一个新的pod( --watch观察pod重建状态变化)

删除deployment


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值