如何为某些节点分配名称空间? [英] How to assign a namespace to certain nodes?

查看:106
本文介绍了如何为某些节点分配名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在名称空间级别配置nodeSelector?

Is there any way to configure nodeSelector at the namespace level?

我只想在此名称空间的某些节点上运行工作负载.

I want to run a workload only on certain nodes for this namespace.

推荐答案

要实现此目的,您可以使用PodNodeSelector准入控制器.

To achieve this you can use PodNodeSelector admission controller.

首先,您需要在 kubernetes-apiserver 中启用它:

First, you need to enable it in your kubernetes-apiserver:

  • 编辑/etc/kubernetes/manifests/kube-apiserver.yaml:
    • 找到--enable-admission-plugins=
    • 添加PodNodeSelector参数
    • Edit /etc/kubernetes/manifests/kube-apiserver.yaml:
      • find --enable-admission-plugins=
      • add PodNodeSelector parameter

      现在,您可以在名称空间的注释中指定scheduler.alpha.kubernetes.io/node-selector选项,例如:

      Now, you can specify scheduler.alpha.kubernetes.io/node-selector option in annotations for your namespace, example:

      apiVersion: v1
      kind: Namespace
      metadata:
       name: your-namespace
       annotations:
         scheduler.alpha.kubernetes.io/node-selector: env=test
      spec: {}
      status: {}
      

      完成这些步骤后,在此命名空间中创建的所有pod都会自动添加此部分:

      After these steps, all the pods created in this namespace will have this section automatically added:

      nodeSelector
        env: test
      

      有关PodNodeSelector的更多信息,您可以在Kubernetes官方文档中找到: https://kubernetes.io/docs/reference/access -authn-authz/admission-controllers/#podnodeselector

      More information about the PodNodeSelector you can find in the official Kubernetes documentation: https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#podnodeselector

      如果您使用kubeadm部署了集群,并且想要使此配置持久化,则必须更新kubeadm配置文件:

      If you deployed your cluster using kubeadm and if you want to make this configuration persistent, you have to update your kubeadm config file:

      kubectl edit cm -n kube-system kubeadm-config
      

      apiServer部分下用自定义值指定extraArgs:

      specify extraArgs with custom values under apiServer section:

      apiServer: 
        extraArgs: 
          enable-admission-plugins: NodeRestriction,PodNodeSelector
      

      然后在所有控制平面节点上更新您的kube-apiserver静态清单:

      then update your kube-apiserver static manifest on all control-plane nodes:

      kubeadm config view > kubeadm-config.yaml
      kubeadm init phase control-plane apiserver --config kubeadm-config.yaml
      


      kubespray用户

      您可以仅将kube_apiserver_enable_admission_plugins变量用作api-server配置变量:


      kubespray users

      You can just use kube_apiserver_enable_admission_plugins variable for your api-server configuration variables:

       kube_apiserver_enable_admission_plugins:
         - PodNodeSelector
      

      这篇关于如何为某些节点分配名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆