zoukankan      html  css  js  c++  java
  • K8S概念理解

    Master 负责管理集群 负责协调集群中的所有活动,例如调度应用程序,维护应用程序的状态,扩展和更新应用程序。
    
    Worker节点是VM(虚拟机)或物理计算机,充当k8s集群中的工作计算机。 
    每个Worker节点都有一个Kubelet,它管理一个Worker节点并与负责与Master节点通信。该Worker节点还应具有用于处理容器操作的工具,例如Docker。
    
    
    执行命令 kubectl get namespaces 可以查看名称空间
    
    执行 kubectl 命令时,可以使用 --namespace 参数指定名称空间,例如:
    
    kubectl run nginx --image=nginx --namespace=<您的名称空间>
    kubectl get pods --namespace=<您的名称空间>
    
    可以通过 set-context 命令改变当前 kubectl 上下文 的名称空间,后续所有命令都默认在此名称空间下执行。
    
    kubectl config set-context --current --namespace=<您的名称空间>
    # 验证结果
    kubectl config view --minify | grep namespace:
    
    执行一下命令可查看哪些 Kubernetes 对象在名称空间里,哪些不在:
    
    # 在名称空间里
    kubectl api-resources --namespaced=true
    
    # 不在名称空间里
    kubectl api-resources --namespaced=false
    
    
    
    
    kubectl 是 k8s 的客户端工具,可以使用命令行管理集群
    
    Deployment 译名为 部署。在k8s中,通过发布 Deployment,可以创建应用程序 (docker image) 的实例 (docker container),这个实例会被包含在称为 Pod 的概念中,Pod 是 k8s 中最小单元的可管理单元。
    
    在 k8s 集群中发布 Deployment 后,Deployment 将指示 k8s 如何创建和更新应用程序的实例,master 节点将应用程序实例调度到集群中的具体的节点上。
    
    创建应用程序实例后,Kubernetes Deployment Controller 会持续监控这些实例。如果运行实例的 worker 节点关机或被删除,则 Kubernetes Deployment Controller 将在群集中资源最优的另一个 worker 节点上重新创建一个新的实例。这提供了一种自我修复机制来解决机器故障或维护问题。
    
    Deployment 处于 master 节点上,通过发布 Deployment,master 节点会选择合适的 worker 节点创建 Container,Container 会被包含在 Pod 里。
    
    创建 Deployment 后,k8s创建了一个 Pod(容器组) 来放置应用程序实例(container 容器)
    
    Kubernetes Pods(容器组)
    
    Pod 容器组 是一个k8s中一个抽象的概念,用于存放一组 container(可包含一个或多个 container 容器),以及这些 container (容器)的一些共享资源
    这些资源包括:
    	共享存储,称为卷(Volumes)
    	网络,每个 Pod(容器组)在集群中有个唯一的 IP,pod(容器组)中的 container(容器)共享该IP地址
    	container(容器)的基本信息,例如容器的镜像版本,对外暴露的端口等
    
    Pod(容器组)是 k8s 集群上的最基本的单元。当我们在 k8s 上创建 Deployment 时,会在集群上创建包含容器的 Pod (而不是直接创建容器)。每个Pod都与运行它的 worker 点(Node)绑定,并保持在那里直到终止或被删除。如果节点(Node)发生故障,则会在群集中的其他可用节点(Node)上运行相同的 Pod(从同样的镜像创建 Container,使用同样的配置,IP 地址不同,Pod 名字不同)。
    
    Pod 是一组容器(可包含一个或多个应用程序容器),以及共享存储(卷 Volumes)、IP 地址和有关如何运行容器的信息。
    如果多个容器紧密耦合并且需要共享磁盘等资源,则他们应该被部署在同一个Pod(容器组)中。
    
    
    Kubernetes Nodes(节点)
    
    执行以下命令可查看所有节点的列表:
    
    kubectl get nodes -o wide
    
    执行以下命令可查看节点状态以及节点的其他详细信息:
    
    kubectl describe node <your-node-name>
    
    
    
    
    Pod(容器组)总是在 Node(节点) 上运行。Node(节点)是 kubernetes 集群中的计算机,可以是虚拟机或物理机。每个 Node(节点)都由 master 管理。一个 Node(节点)可以有多个Pod(容器组),kubernetes master 会根据每个 Node(节点)上可用资源的情况,自动调度 Pod(容器组)到最佳的 Node(节点)上。
    
    每个 Kubernetes Node(节点)至少运行:
        Kubelet,负责 master 节点和 worker 节点之间通信的进程;管理 Pod(容器组)和 Pod(容器组)内运行的 Container(容器)。
        容器运行环境(如Docker)负责下载镜像、创建和运行容器等。
    
    
    
    Kubernetes 中的 Service(服务) 提供了这样的一个抽象层,它选择具备某些特征的 Pod(容器组)并为它们定义一个访问方式。Service(服务)使 Pod(容器组)之间的相互依赖解耦(原本从一个 Pod 中访问另外一个 Pod,需要知道对方的 IP 地址)。一个 Service(服务)选定哪些 Pod(容器组) 通常由 LabelSelector(标签选择器) 来决定。
    
    在创建Service的时候,通过设置配置文件中的 spec.type 字段的值,可以以不同方式向外部暴露应用程序:
    
        ClusterIP(默认)
        在群集中的内部IP上公布服务,这种方式的 Service(服务)只在集群内部可以访问到
    
        NodePort
        使用 NAT 在集群中每个的同一端口上公布服务。这种方式下,可以通过访问集群中任意节点+端口号的方式访问服务 <NodeIP>:<NodePort>。此时 ClusterIP 的访问方式仍然可用。
    
        LoadBalancer
        在云环境中(需要云供应商可以支持)创建一个集群外部的负载均衡器,并为使用该负载均衡器的 IP 地址作为服务的访问地址。此时 ClusterIP 和 NodePort 的访问方式仍然可用。
    
    
    Rolling Update滚动更新 通过使用新版本的 Pod 逐步替代旧版本的 Pod 来实现 Deployment 的更新,从而实现零停机。新的 Pod 将在具有可用资源的 Node(节点)上进行调度。
    
    Kubernetes 更新多副本的 Deployment 的版本时,会逐步的创建新版本的 Pod,逐步的停止旧版本的 Pod,以便使应用一直处于可用状态。这个过程中,Service 能够监视 Pod 的状态,将流量始终转发到可用的 Pod 上。
    
    默认情况下,Rolling Update 滚动更新 过程中,Kubernetes 逐个使用新版本 Pod 替换旧版本 Pod(最大不可用 Pod 数为 1、最大新建 Pod 数也为 1)。这两个参数可以配置为数字或百分比。在Kubernetes 中,更新是版本化的,任何部署更新都可以恢复为以前的(稳定)版本。
    
    滚动更新允许以下操作:
    
        将应用程序从准上线环境升级到生产环境(通过更新容器镜像)
        回滚到以前的版本
        持续集成和持续交付应用程序,无需停机
    
    
    查看名称空间:kubectl get namespace
    
    
    创建名称空间:kubectl create namespace test_hkd
    查看详细信息:kubectl describe namespace test_hkd
    
    
    
    使用 kubectl api-versions 即可查看当前集群支持的版本
    
    应用 YAML 文件: kubectl apply -f nginx-deployment.yaml
    
    kubectl get - 显示资源列表
    
    # kubectl get 资源类型
    
    #获取类型为Deployment的资源列表
    kubectl get deployments
    
    #获取类型为Pod的资源列表
    kubectl get pods
    
    #获取类型为Node的资源列表
    kubectl get nodes
    
    kubectl describe - 显示有关资源的详细信息
    
    # kubectl describe 资源类型 资源名称
    
    #查看名称为nginx-XXXXXX的Pod的信息
    kubectl describe pod nginx-XXXXXX	
    
    #查看名称为nginx的Deployment的信息
    kubectl describe deployment nginx	
    
    kubectl logs - 查看pod中的容器的打印日志(和命令docker logs 类似)
    
    # kubectl logs Pod名称
    
    #查看名称为nginx-pod-XXXXXXX的Pod内的容器打印的日志
    #本案例中的 nginx-pod 没有输出日志,所以您看到的结果是空的
    kubectl logs -f nginx-pod-XXXXXXX
    
    kubectl exec - 在pod中的容器环境内执行命令(和命令docker exec 类似)
    
    # kubectl exec Pod名称 操作命令
    
    # 在名称为nginx-pod-xxxxxx的Pod中运行bash
    kubectl exec -it nginx-pod-xxxxxx /bin/bash
    
    
    ####
    kubectl controls the Kubernetes cluster manager.
    
     Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
    
    Basic Commands (Beginner):
      create         Create a resource from a file or from stdin.
      expose         Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
      run            Run a particular image on the cluster
      set            Set specific features on objects
    
    Basic Commands (Intermediate):
      explain        Documentation of resources
      get            Display one or many resources
      edit           Edit a resource on the server
      delete         Delete resources by filenames, stdin, resources and names, or by resources and label selector
    
    Deploy Commands:
      rollout        Manage the rollout of a resource
      scale          Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job
      autoscale      Auto-scale a Deployment, ReplicaSet, or ReplicationController
    
    Cluster Management Commands:
      certificate    Modify certificate resources.
      cluster-info   Display cluster info
      top            Display Resource (CPU/Memory/Storage) usage.
      cordon         Mark node as unschedulable
      uncordon       Mark node as schedulable
      drain          Drain node in preparation for maintenance
      taint          Update the taints on one or more nodes
    
    Troubleshooting and Debugging Commands:
      describe       Show details of a specific resource or group of resources
      logs           Print the logs for a container in a pod
      attach         Attach to a running container
      exec           Execute a command in a container
      port-forward   Forward one or more local ports to a pod
      proxy          Run a proxy to the Kubernetes API server
      cp             Copy files and directories to and from containers.
      auth           Inspect authorization
    
    Advanced Commands:
      diff           Diff live version against would-be applied version
      apply          Apply a configuration to a resource by filename or stdin
      patch          Update field(s) of a resource using strategic merge patch
      replace        Replace a resource by filename or stdin
      wait           Experimental: Wait for a specific condition on one or many resources.
      convert        Convert config files between different API versions
      kustomize      Build a kustomization target from a directory or a remote url.
    
    Settings Commands:
      label          Update the labels on a resource
      annotate       Update the annotations on a resource
      completion     Output shell completion code for the specified shell (bash or zsh)
    
    Other Commands:
      api-resources  Print the supported API resources on the server
      api-versions   Print the supported API versions on the server, in the form of "group/version"
      config         Modify kubeconfig files
      plugin         Provides utilities for interacting with plugins.
      version        Print the client and server version information
    
    Usage:
      kubectl [flags] [options]
    
    Use "kubectl <command> --help" for more information about a given command.
    Use "kubectl options" for a list of global command-line options (applies to all commands).
    
    ####
    
  • 相关阅读:
    外设简述
    代C语言上机实践
    css动画效果
    css滑动门原理
    css整理
    html
    html单词
    倒计时.js
    随机方块
    求字符串出现次数和最大值
  • 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/12187129.html
Copyright © 2011-2022 走看看