• 云原生FAQ


    Kubernetes

    Annotation

    Annotation(注解)是另一种附加在对象之上的键值类型的数据,但它拥有更大的数据容量。Annotation常用于将各种非标识型元数据(metadata)附加到对象上,但它不能用于标识和选择对象,通常也不会被Kubernetes直接使用,其主要目的是方便工具或用户的阅读及查找等。

    service (服务暴露)

    service 为pod提供统一的访问入口并实现负载均衡
    ClusterIP、 NodePort、 LoadBalance、 ExternalName
    在这里插入图片描述
    https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types

    Ingress

    Kubernetes将Pod对象和外部网络环境进行了隔离, Pod和Service等对象间的通信都使用其内部专用地址进行,如若需要开放某些Pod对象提供给外部用户访问,则需要为其请求流量打开一个通往Kubernetes集群内部的通道,除了Service之外, Ingress也是这类通道的实现方式之一。

    Kubernets 集群组件

    在这里插入图片描述
    API Server:负责输出Restful 风格的Kubernetes API,集群网关
    etcd:集群状态存储,分布式key-value数据库,有watch监听机制
    Controller-manager:控制器管理器,资源生命周期管理,API业务逻辑
    Scheduler: 响应资源请求,并调度到合适的工作负载节点
    Kubelet:工作节点的守护进程,响应API Server的请求,并定期向master汇报节点的资源使用情况
    容器运行时环境: Container Runtime
    Kube-Proxy: 为service资源对象生成iptables或ipvs规则,流量转发
    CoreDNS:提供DNS服务
    Kubernetes Dashboard: web UI
    Heapster: 容器和节点的性能监控与分析系统,被prometheus取代
    Ingress Controller: Ingress实现HTTP(s)的负载均衡,也就是level 7 lb, services实现的是L4 lb

    任意节点使用kubectl

    复制 master 上的/etc/kubernetes/admin.conf到相关主机的home下面的.kube/config文件中

    Kubernets的资源对象

    [root@host49 ~]# kubectl api-resources
    NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
    bindings                                                                      true         Binding
    componentstatuses                 cs                                          false        ComponentStatus
    configmaps                        cm                                          true         ConfigMap
    endpoints                         ep                                          true         Endpoints
    events                            ev                                          true         Event
    limitranges                       limits                                      true         LimitRange
    namespaces                        ns                                          false        Namespace
    nodes                             no                                          false        Node
    persistentvolumeclaims            pvc                                         true         PersistentVolumeClaim
    persistentvolumes                 pv                                          false        PersistentVolume
    pods                              po                                          true         Pod
    podtemplates                                                                  true         PodTemplate
    replicationcontrollers            rc                                          true         ReplicationController
    resourcequotas                    quota                                       true         ResourceQuota
    secrets                                                                       true         Secret
    serviceaccounts                   sa                                          true         ServiceAccount
    services                          svc                                         true         Service
    mutatingwebhookconfigurations                  admissionregistration.k8s.io   false        MutatingWebhookConfiguration
    validatingwebhookconfigurations                admissionregistration.k8s.io   false        ValidatingWebhookConfiguration
    customresourcedefinitions         crd,crds     apiextensions.k8s.io           false        CustomResourceDefinition
    apiservices                                    apiregistration.k8s.io         false        APIService
    aplogconfs                                     appprotect.f5.com              true         APLogConf
    appolicies                                     appprotect.f5.com              true         APPolicy
    apusersigs                                     appprotect.f5.com              true         APUserSig
    controllerrevisions                            apps                           true         ControllerRevision
    daemonsets                        ds           apps                           true         DaemonSet
    deployments                       deploy       apps                           true         Deployment
    replicasets                       rs           apps                           true         ReplicaSet
    statefulsets                      sts          apps                           true         StatefulSet
    tokenreviews                                   authentication.k8s.io          false        TokenReview
    localsubjectaccessreviews                      authorization.k8s.io           true         LocalSubjectAccessReview
    selfsubjectaccessreviews                       authorization.k8s.io           false        SelfSubjectAccessReview
    selfsubjectrulesreviews                        authorization.k8s.io           false        SelfSubjectRulesReview
    subjectaccessreviews                           authorization.k8s.io           false        SubjectAccessReview
    horizontalpodautoscalers          hpa          autoscaling                    true         HorizontalPodAutoscaler
    cronjobs                          cj           batch                          true         CronJob
    jobs                                           batch                          true         Job
    apps                                           catalog.cattle.io              true         App
    clusterrepos                                   catalog.cattle.io              false        ClusterRepo
    operations                                     catalog.cattle.io              true         Operation
    certificatesigningrequests        csr          certificates.k8s.io            false        CertificateSigningRequest
    clusterauthtokens                              cluster.cattle.io              true         ClusterAuthToken
    clusteruserattributes                          cluster.cattle.io              true         ClusterUserAttribute
    leases                                         coordination.k8s.io            true         Lease
    endpointslices                                 discovery.k8s.io               true         EndpointSlice
    events                            ev           events.k8s.io                  true         Event
    ingresses                         ing          extensions                     true         Ingress
    globalconfigurations              gc           k8s.nginx.org                  true         GlobalConfiguration
    policies                          pol          k8s.nginx.org                  true         Policy
    transportservers                  ts           k8s.nginx.org                  true         TransportServer
    virtualserverroutes               vsr          k8s.nginx.org                  true         VirtualServerRoute
    virtualservers                    vs           k8s.nginx.org                  true         VirtualServer
    clusters                                       management.cattle.io           false        Cluster
    features                                       management.cattle.io           false        Feature
    preferences                                    management.cattle.io           true         Preference
    settings                                       management.cattle.io           false        Setting
    nodes                                          metrics.k8s.io                 false        NodeMetrics
    pods                                           metrics.k8s.io                 true         PodMetrics
    alertmanagers                                  monitoring.coreos.com          true         Alertmanager
    prometheuses                                   monitoring.coreos.com          true         Prometheus
    prometheusrules                                monitoring.coreos.com          true         PrometheusRule
    servicemonitors                                monitoring.coreos.com          true         ServiceMonitor
    ingressclasses                                 networking.k8s.io              false        IngressClass
    ingresses                         ing          networking.k8s.io              true         Ingress
    networkpolicies                   netpol       networking.k8s.io              true         NetworkPolicy
    runtimeclasses                                 node.k8s.io                    false        RuntimeClass
    poddisruptionbudgets              pdb          policy                         true         PodDisruptionBudget
    podsecuritypolicies               psp          policy                         false        PodSecurityPolicy
    clusterrolebindings                            rbac.authorization.k8s.io      false        ClusterRoleBinding
    clusterroles                                   rbac.authorization.k8s.io      false        ClusterRole
    rolebindings                                   rbac.authorization.k8s.io      true         RoleBinding
    roles                                          rbac.authorization.k8s.io      true         Role
    priorityclasses                   pc           scheduling.k8s.io              false        PriorityClass
    csidrivers                                     storage.k8s.io                 false        CSIDriver
    csinodes                                       storage.k8s.io                 false        CSINode
    storageclasses                    sc           storage.k8s.io                 false        StorageClass
    volumeattachments                              storage.k8s.io                 false        VolumeAttachment
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80

    资源及其在API中的组织形式

    资源类型 GROUP/VERSION/RESOURCE
    资源路径
    /apis/< group>/ < version >/namespaces/< namespace> / < kind-plural>

    [root@host49 ~]# kubectl api-versions
    admissionregistration.k8s.io/v1
    admissionregistration.k8s.io/v1beta1
    apiextensions.k8s.io/v1
    apiextensions.k8s.io/v1beta1
    apiregistration.k8s.io/v1
    apiregistration.k8s.io/v1beta1
    appprotect.f5.com/v1beta1
    apps/v1
    authentication.k8s.io/v1
    authentication.k8s.io/v1beta1
    authorization.k8s.io/v1
    authorization.k8s.io/v1beta1
    autoscaling/v1
    autoscaling/v2beta1
    autoscaling/v2beta2
    batch/v1
    batch/v1beta1
    catalog.cattle.io/v1
    certificates.k8s.io/v1
    certificates.k8s.io/v1beta1
    cluster.cattle.io/v3
    coordination.k8s.io/v1
    coordination.k8s.io/v1beta1
    discovery.k8s.io/v1beta1
    events.k8s.io/v1
    events.k8s.io/v1beta1
    extensions/v1beta1
    k8s.nginx.org/v1
    k8s.nginx.org/v1alpha1
    management.cattle.io/v3
    metrics.k8s.io/v1beta1
    monitoring.coreos.com/v1
    networking.k8s.io/v1
    networking.k8s.io/v1beta1
    node.k8s.io/v1beta1
    policy/v1beta1
    rbac.authorization.k8s.io/v1
    rbac.authorization.k8s.io/v1beta1
    scheduling.k8s.io/v1
    scheduling.k8s.io/v1beta1
    storage.k8s.io/v1
    storage.k8s.io/v1beta1
    v1
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    容器镜像拉取策略

    Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always
    https://kubernetes.io/docs/concepts/containers/images#updating-images

    [root@host49 ~]# kubectl explain pod.spec.containers.imagePullPolicy
    KIND:     Pod
    VERSION:  v1
    
    FIELD:    imagePullPolicy <string>
    
    DESCRIPTION:
         Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always
         if :latest tag is specified, or IfNotPresent otherwise. Cannot be updated.
         More info:
         https://kubernetes.io/docs/concepts/containers/images#updating-images
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    Pod重启策略

    Always, OnFailure,Never
    https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy

    [root@host49 ~]# kubectl explain pod.spec.restartPolicy
    KIND:     Pod
    VERSION:  v1
    
    FIELD:    restartPolicy <string>
    
    DESCRIPTION:
         Restart policy for all containers within the pod. One of Always, OnFailure,
         Never. Default to Always. More info:
         https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    docker cli

    docker cli

    Docker Hub Container Image Library

    https://hub.docker.com/
    https://hub.daocloud.io/

    Pod对象的生命周期

    [root@host49 ~]# kubectl explain pod.status.phase
    DESCRIPTION:
    The phase of a Pod is a simple, high-level summary of where the Pod is in
    its lifecycle. The conditions array, the reason and message fields, and the
    individual container status arrays contain more detail about the pod’s
    status. There are five possible phase values:
    Pending: The pod has been accepted by the Kubernetes system, but one or more of the container images has not been created. This includes time before being scheduled as well as time spent downloading images over the network, which could take a while.
    Running: The pod has been bound to a node, and all of the containers have been created. At least one container is still running, or is in the process of starting or restarting.
    Succeeded: All containers in the pod have terminated in success, and will not be restarted.
    Failed: All containers in the pod have terminated, and at least one container has terminated in
    failure. The container either exited with non-zero status or was terminated
    by the system.
    Unknown: For some reason the state of the pod could not be obtained, typically due to an error in communicating with the host of the pod.
    More info:
    https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-phase

    在这里插入图片描述

    liveness probe

    exec 探针
    http探针
    tcp探针

    [root@host49 ~]# kubectl explain pod.spec.containers.livenessProbe
    KIND:     Pod
    VERSION:  v1
    
    RESOURCE: livenessProbe <Object>
    
    DESCRIPTION:
         Periodic probe of container liveness. Container will be restarted if the
         probe fails. Cannot be updated. More info:
         https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
    
         Probe describes a health check to be performed against a container to
         determine whether it is alive or ready to receive traffic.
    
    FIELDS:
       exec <Object>
         One and only one of the following should be specified. Exec specifies the
         action to take.
    
       failureThreshold     <integer>
         Minimum consecutive failures for the probe to be considered failed after
         having succeeded. Defaults to 3. Minimum value is 1.
    
       httpGet      <Object>
         HTTPGet specifies the http request to perform.
    
       initialDelaySeconds  <integer>
         Number of seconds after the container has started before liveness probes
         are initiated. More info:
         https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
    
       periodSeconds        <integer>
         How often (in seconds) to perform the probe. Default to 10 seconds. Minimum
         value is 1.
    
       successThreshold     <integer>
         Minimum consecutive successes for the probe to be considered successful
         after having failed. Defaults to 1. Must be 1 for liveness and startup.
         Minimum value is 1.
    
       tcpSocket    <Object>
         TCPSocket specifies an action involving a TCP port. TCP hooks not yet
         supported
    
       timeoutSeconds       <integer>
         Number of seconds after which the probe times out. Defaults to 1 second.
         Minimum value is 1. More info:
         https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    readiness probe

    exec 探针
    http探针
    tcp探针

    [root@host49 ~]# kubectl explain pod.spec.containers.readinessProbe
    KIND:     Pod
    VERSION:  v1
    
    RESOURCE: readinessProbe <Object>
    
    DESCRIPTION:
         Periodic probe of container service readiness. Container will be removed
         from service endpoints if the probe fails. Cannot be updated. More info:
         https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
    
         Probe describes a health check to be performed against a container to
         determine whether it is alive or ready to receive traffic.
    
    FIELDS:
       exec <Object>
         One and only one of the following should be specified. Exec specifies the
         action to take.
    
       failureThreshold     <integer>
         Minimum consecutive failures for the probe to be considered failed after
         having succeeded. Defaults to 3. Minimum value is 1.
    
       httpGet      <Object>
         HTTPGet specifies the http request to perform.
    
       initialDelaySeconds  <integer>
         Number of seconds after the container has started before liveness probes
         are initiated. More info:
         https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
    
       periodSeconds        <integer>
         How often (in seconds) to perform the probe. Default to 10 seconds. Minimum
         value is 1.
    
       successThreshold     <integer>
         Minimum consecutive successes for the probe to be considered successful
         after having failed. Defaults to 1. Must be 1 for liveness and startup.
         Minimum value is 1.
    
       tcpSocket    <Object>
         TCPSocket specifies an action involving a TCP port. TCP hooks not yet
         supported
    
       timeoutSeconds       <integer>
         Number of seconds after which the probe times out. Defaults to 1 second.
         Minimum value is 1. More info:
         https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    存储卷

    [root@host49 ~]# kubectl explain pod.spec.volumes  | grep Object
    RESOURCE: volumes <[]Object>
       awsElasticBlockStore <Object>
       azureDisk    <Object>
       azureFile    <Object>
       cephfs       <Object>
       cinder       <Object>
       configMap    <Object>
       csi  <Object>
       downwardAPI  <Object>
       emptyDir     <Object>
       ephemeral    <Object>
       fc   <Object>
       flexVolume   <Object>
       flocker      <Object>
       gcePersistentDisk    <Object>
       gitRepo      <Object>
       glusterfs    <Object>
       hostPath     <Object>
       iscsi        <Object>
       nfs  <Object>
       persistentVolumeClaim        <Object>
       photonPersistentDisk <Object>
       portworxVolume       <Object>
       projected    <Object>
       quobyte      <Object>
       rbd  <Object>
       scaleIO      <Object>
       secret       <Object>
       storageos    <Object>
       vsphereVolume        <Object>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    Role & RoleBonding

    Role 主要强调角色的定义,比如什么角色操作资源的具体权限;
    RoleBonding 则 强调的是具体实例绑定到摸个Role中
    Subject —> action(verb) —>object
    subject : user account, service account
    verb: create , delete, update,apply,patch
    object 为资源对象

    Role example

    ##Role example ###
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      namespace: default
      name: pod-reader
    rules:
    - apiGroups: [""] # "" 标明 core API 组
      resources: ["pods"]
      verbs: ["get", "watch", "list"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    RoleBonding

      
    ###RoleBonding ####
    apiVersion: rbac.authorization.k8s.io/v1
    # 此角色绑定允许 "jane" 读取 "default" 名字空间中的 Pod
    # 你需要在该命名空间中有一个名为 “pod-reader” 的 Role
    kind: RoleBinding
    metadata:
      name: read-pods
      namespace: default
    subjects:
    # 你可以指定不止一个“subject(主体)”
    - kind: User
      name: jane # "name" 是区分大小写的
      apiGroup: rbac.authorization.k8s.io
    roleRef:
      # "roleRef" 指定与某 Role 或 ClusterRole 的绑定关系
      kind: Role        # 此字段必须是 Role 或 ClusterRole
      name: pod-reader  # 此字段必须与你要绑定的 Role 或 ClusterRole 的名称匹配
      apiGroup: rbac.authorization.k8s.io
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
  • 相关阅读:
    Erdos-Renyi随机图的生成方式及其特性
    java基于springboot实验室预约设备报修管理系统fu1ju
    ant design vue对话框关闭数据清空
    即兴发言怎样避免语无伦次?记住这个即兴发言万能公式
    推荐系统方法梳理
    链表问题 — — 高频面试题【LeetCode - 138】
    Rust中FnOnce如何传递给一个约束Fn的回调
    基于Java的剧本杀预约系统设计与实现(源码+lw+部署文档+讲解等)
    【华为OD机试真题 JAVA】磁盘容量排序
    Python:Choosing Colormaps in Matplotlib
  • 原文地址:https://blog.csdn.net/yolo2016/article/details/126059703