陈述式资管管理
管理名称空间资源
查看名称空间
$ 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