kubeclt命令

 

1,命令

陈述式资源管理方法:
命令
#kubectl get namespace
#kubectl get ns
#kubectl get all  (-n default)
#kubectl get create ns   app
#kubectl delete namespace app
#kubectl create deployment nginx-dp --image=harbor.od.com/public/nginx:1.7.9 -n kube-public
#kubect get deploy -n kube-public
#kubectl get deployment  -o wide -n kube-public
#kubuctl describe deployment nginx-dp -n kube-public
#kubuctl get pods -n kube-public
#kubuctl exec -ti nginx-dp /bin/bash -n kube-public
#docker ps -a |grep nginx-dp
#watch -n 1 'kubectl describe deployment nginx-dp -n kube-public |grep -C 5 Event'
#kubectl delete pod nginx-dp  -n kube-public
#kubectl get all -n kube-public
# kubectl expose deployment nginx-dp --port=80 -n kube-public 创建service
# ipvsadm -Ln
# kubectl scale deployment nginx-dp --replicas=2 -n kube-public
# kubectl scale deployment nginx-dp --replicas=1 -n kube-public
# kubectl get svc -n kube-public 查看service
# kubectl describe svc nginx-dp -n kube-public

#kubectl delete svc nginx-ds 陈述式删除



 

声明式资源管理方法
# kubectl get pods nginx-dp-5dfc689474-pv94b -o yaml -n kube-public
# kubectl get service -n kube-public
# kubectl get svc -n kube-public
# kubectl get svc nginx-dp -o yaml -n kube-public  查看资源配置清单方法
# kubectl explain service.metadata  解释资源清单


# cat nginx-ds-svc.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx-ds
  name: nginx-ds
  namespace: default
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-ds
  sessionAffinity: None
  type: ClusterIP

# kubectl create -f nginx-ds-svc.yaml  或 #kubectl apply -f nginx-ds-svc.yaml  应用资源配置清单
# kubectl get svc
# kubectl get svc -n default
# kubectl get svc nginx-dss -o yaml
在线修改nginx-ds-svc.yaml 
#kubectl edit svc nginx-ds
离线修改nginx-ds-svc.yaml 
#kubectl apply -f nginx-ds-svc.yaml 
#kubectl describe ds nginx-ds

#kubectl delete -f nginx-ds-svc.yaml 声明式删除
#kubectl get svc -n kube-public

  

  

 

2,问题

(1)

]# kubectl get pods -n kube-public
NAME                        READY   STATUS    RESTARTS   AGE
nginx-dp-5dfc689474-pv94b   0/1     Pending   0          3m21s
Every 1.0s: kubectl describe deployment nginx-dp -n kube-public |grep -C 5 Event                                                                                       Sun Nov 21 21:36:29 2021

  ----           ------  ------
  Available      False   MinimumReplicasUnavailable
  Progressing    True    ReplicaSetUpdated
OldReplicaSets:  <none>
NewReplicaSet:   nginx-dp-5dfc689474 (1/1 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  5m53s  deployment-controller  Scaled up replica set nginx-dp-5dfc689474 to 1

 

参考链接:https://www.cnblogs.com/gshelldon/p/14734629.html 

 

 

yaml

apiversion: v1              #pod 接口
kind:Pod			  #控制器名词pod
metadata
  name;nginx		   #pod名词
  labels:
    app;nginx               #pod标签  app=nginx
spec:
  containers:
  - name: nginx           #容器名词
    image:ngnix          #镜像名称
	ports:
	- containerPort: 80       #容器端口
	  hostPort:3000           #node端口


  

 

Pod启动与存活机制
apiVersion: apps/v1  #控制器接口版本
kind: Deployment     #控制器类型
metadata:
  name: nginx-deployment #Deployment控制器名称
  lables:
    app: nginx-deployment  #控制器标签
spec:
  replicas: 3              #Deployment副本数量(容器数量)
  selector:
    matchLables:
      app: nginx-deployment #标签选择器
  minReadySecounds: 1       #pod 准备时间
  strategy:
    type: RollingUpdate     #pod 升级策略
    rollingUpdate:
      maxSurge: 1           #最大允许1个pod升级
      maxUnavailable: 1     #最多允许一个pod失效
  template:
    metadata:
      lables:
        app: nginx-deployment #模板标签
    spec:
      containers:
      - name: nginx-deployment #容器名称
        image: nginx:latest     #镜像名称
        ports:
        - containerPort: 80     #容器端口
        readinessProbe:         #容器就绪检测
          tcpSocket:
            port: 80
          initialDelaySecounds: 5  #容器启动后5秒检测
          periodSeconds: 10      #容器初始化之后每隔10秒检测

  






posted on 2021-11-21 21:52  微子天明  阅读(35)  评论(0编辑  收藏  举报

导航