zoukankan      html  css  js  c++  java
  • 11. 搭建一个完整的K8S集群

    11. 搭建一个完整的Kubernetes集群

    1. kubectl的命令遵循分类的原则(重点)

    语法1:

    kubectl 动作 具体的对象

    例如:

    """
    kubectl describe node  master
    
    describe	描述,相当于语法中的动作
    node		node资源,相当于语法中的类,对某一类资源的统称
    master		node资源中的一个叫master资源,相当于语法中的具体对象
    """
    

    语法2:

    kubectl 动作 大范围参数 细化参数 ...

    例如:

    """
    kubectl get pods  -n  kube-system  -o  wide
    
    -n	表示  namespace(命名空间)
    kube-system  表示 多个命名空间中的一个命名空间
    -o	
    wide	更加全面的展示信息
    """
    

    2. Master节点是通过什么技术来限制用户不允许运行用户自己的pod的?

    默认情况下 Master 节点是不允许运行用户 Pod 的。而 Kubernetes 做到这一点,依靠的是 Kubernetes 的 Taint/Toleration 机制

    它的原理非常简单:一旦某个节点被加上了一个 Taint(污点),即被“打上了污点”,那么所有 Pod 就都不能在这个节点上运行,因为 Kubernetes 的 Pod 都有“洁癖”

    除非,有个别的 Pod 声明自己能“容忍”这个“污点”,即声明了 Toleration,它才可以在这个节点上运行。

    其中,为节点打上“污点”(Taint)的命令是:

    kubectl taint nodes node1 foo=bar:NoSchedule
    

    这时,该 node1 节点上就会增加一个键值对格式的 Taint,即:foo=bar:NoSchedule。其中值里面的 NoSchedule,意味着这个 Taint 只会在调度新 Pod 时产生作用,而不会影响已经在 node1 上运行的 Pod,哪怕它们没有 Toleration。

    那么 Pod 又如何声明 Toleration 呢?

    我们只要在 Pod 的.yaml 文件中的 spec 部分,加入 tolerations 字段即可:

    apiVersion: v1
    kind: Pod
    ...
    spec:
      tolerations:
      - key: "foo"
        operator: "Equal"
        value: "bar"
        effect: "NoSchedule"
    

    这个 Toleration 的含义是,这个 Pod 能“容忍”所有键值对为 foo=bar 的 Taint( operator: “Equal”,“等于”操作)。

    现在回到我们已经搭建的集群上来。这时,如果你通过 kubectl describe 检查一下 Master 节点的 Taint 字段,就会有所发现了:

    $ kubectl describe node master
     
    Name:               master
    Roles:              master
    Taints:             node-role.kubernetes.io/master:NoSchedule
    

    可以看到,Master 节点默认被加上了node-role.kubernetes.io/master:NoSchedule这样一个“污点”,其中“键”是node-role.kubernetes.io/master,而没有提供“值”

    此时,你就需要像下面这样用“Exists”操作符(operator: “Exists”,“存在”即可)来说明,该 Pod 能够容忍所有以 foo 为键的 Taint,才能让这个 Pod 运行在该 Master 节点上:

    apiVersion: v1
    kind: Pod
    ...
    spec:
      tolerations:
      - key: "foo"
        operator: "Exists"
        effect: "NoSchedule"
    

    当然,如果你就是想要一个单节点的 Kubernetes,删除这个 Taint 才是正确的选择

    $ kubectl taint nodes --all node-role.kubernetes.io/master-
    

    如上所示,我们在“node-role.kubernetes.io/master”这个键后面加上了一个短横线“-”,这个格式就意味着移除所有以“node-role.kubernetes.io/master”为键的 Taint

  • 相关阅读:
    ruby 正则表达式 匹配中文
    ruby 正则表达式 匹配所有符合规则的信息
    MobileNetV2: Inverted Residuals and Linear Bottlenecks
    MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
    SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size
    LeetCode 409——最长回文串
    LeetCode 516——最长回文子序列
    LeetCode 5——最长回文子串
    LeetCode 300——最长上升子序列
    动态规划之——最长公共子串和矩阵链乘法
  • 原文地址:https://www.cnblogs.com/plf-Jack/p/11299987.html
Copyright © 2011-2022 走看看