kubernetes集群编排——k8s调度

news2024/10/6 10:32:39

nodename

vim nodename.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx

spec:
  containers:
  - name: nginx
    image: nginx
  nodeName: k8s2

  nodeName: k8s2 #找不到节点pod会出现pending,优先级最高

kubectl apply -f nodename.yaml

kubectl get pod -o wide

回收

kubectl delete -f nodename.yaml

nodeselector

vim nodeselector.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    disktype: ssd
kubectl label  nodes k8s4 disktype=ssd

kubectl label  nodes k8s3 disktype=ssd
kubectl apply -f nodeselector.yaml

回收

kubectl delete -f nodeselector.yaml

nodeaffinity

vim nodeaffinity.yaml
apiVersion: v1
kind: Pod
metadata:
  name: node-affinity
spec:
  containers:
  - name: nginx
    image: nginx
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
           nodeSelectorTerms:
           - matchExpressions:
             - key: disktype
               operator: In
               values:
                 - ssd
                 - fc

      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: kubernetes.io/hostname
            operator: NotIn
            values:
            - k8s3
kubectl apply -f nodeaffinity.yaml
kubectl describe  pod node-affinity

回收

kubectl delete -f nodeaffinity.yaml

podaffinity

vim podaffinity.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nginx
            topologyKey: "kubernetes.io/hostname"
kubectl apply -f podaffinity.yaml

kubectl get pod -o wide

回收

kubectl delete -f podaffinity.yaml

podantiaffinity

vim podantiaffinity.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nginx
            topologyKey: "kubernetes.io/hostname"
kubectl apply -f podantiaffinity.yaml

kubectl get pod -o wide

回收

kubectl delete -f podantiaffinity.yaml

pod反亲和倾向满足

vim poda.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-affinity
spec:
 replicas: 3
 selector:
  matchLabels:
   app: nginx
 template:
  metadata:
   labels:
    app: nginx
  spec:
   tolerations:
   - effect: NoSchedule
     operator: Exists
   - effect: NoExecute
     operator: Exists
   containers:
   - name: nginx
     image: nginx
   affinity:
     podAntiAffinity:
       preferredDuringSchedulingIgnoredDuringExecution:
       - weight: 100
         podAffinityTerm:
           labelSelector:
             matchExpressions:
             - key: app
               operator: In
               values:
               - nginx
           topologyKey: kubernetes.io/hostname

     nodeAffinity:
       requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: disktype
                operator: In
                values:
                  - ssd
                  - sata
kubectl apply -f poda.yaml

kubectl get pod -o wide

回收

kubectl delete -f poda.yaml

Taints

vim taint.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - image: nginx
        name: nginx
kubectl apply -f taint.yaml

kubectl get pod -o wide

设置taint

kubectl taint node k8s3 k1=v1:NoSchedule

kubectl describe nodes  k8s3 |grep Tain

kubectl scale deployment web --replicas 6

kubectl get pod -o wide

kubectl taint node k8s3 k1=v1:NoExecute

kubectl describe nodes  k8s3 |grep Tain

kubectl get pod -o wide

回收

kubectl delete  -f taint.yaml

设置 tolerations

vim taint.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: web
spec:
  replicas: 6
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      tolerations:
      - operator: Exists
        effect: NoSchedule
      containers:
      - image: nginx
        name: nginx
kubectl apply -f taint.yaml

kubectl get pod -o wide

回收

kubectl delete -f taint.yaml

容忍所有taints

vim taint.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: web
spec:
  replicas: 6
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      tolerations:
      - operator: Exists
      containers:
      - image: nginx
        name: nginx
kubectl apply -f taint.yaml

kubectl get pod -o wide

回收

kubectl delete -f taint.yaml

删除taints

kubectl taint  node k8s3 k1-

cordon、drain、delete

kubectl create deployment demo --image nginx --replicas 3

kubectl get pod -o wide

kubectl cordon k8s3

kubectl get node

kubectl scale deployment demo --replicas 6

kubectl get pod -o wide

kubectl drain k8s3 --ignore-daemonsets

kubectl get pod -o wide

kubectl delete nodes k8s3

kubectl get node

k8s3节点重启kubelet服务重新加入集群

[root@k8s3 ~]# systemctl restart kubelet

[root@k8s2 node]# kubectl get node

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1183506.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

AI系统ChatGPT程序源码+AI绘画系统源码+支持GPT4.0+Midjourney绘画+已支持OpenAI GPT全模型+国内AI全模型

一、AI创作系统 SparkAi创作系统是基于OpenAI很火的ChatGPT进行开发的Ai智能问答系统和Midjourney绘画系统,支持OpenAI-GPT全模型国内AI全模型。本期针对源码系统整体测试下来非常完美,可以说SparkAi是目前国内一款的ChatGPT对接OpenAI软件系统。那么如…

VMware创建Linux虚拟机之(三)Hadoop安装与配置及搭建集群

Hello,world! 🐒本篇博客使用到的工具有:VMware16 ,Xftp7 若不熟悉操作命令,推荐使用带GUI页面的CentOS7虚拟机 我将使用带GUI页面的虚拟机演示 虚拟机(Virtual Machine) 指通过…

2023年【安全员-A证】最新解析及安全员-A证在线考试

题库来源:安全生产模拟考试一点通公众号小程序 安全员-A证最新解析是安全生产模拟考试一点通生成的,安全员-A证证模拟考试题库是根据安全员-A证最新版教材汇编出安全员-A证仿真模拟考试。2023年【安全员-A证】最新解析及安全员-A证在线考试 1、【多选题…

计算机毕业设计项目选题推荐(免费领源码)java+ssm+Mysq学科竞赛管理系统08604

摘 要 21世纪的今天,随着社会的不断发展与进步,人们对于信息科学化的认识,已由低层次向高层次发展,由原来的感性认识向理性认识提高,管理工作的重要性已逐渐被人们所认识,科学化的管理,使信息存…

学编程始于C语言,但只学C远远不够的!

前言 写了20多年的代码,之前做过阿里的高级架构师,在技术这条路上跌跌撞撞了很多,我今天分享一些我个人的自学方法给各位。为什么我会说:不推荐任何人用C语言作为编程启蒙第一课? 这里有很多同学要站出来说了&#x…

rabbitMQ rascal/amqplib报错 Error: Unexpected close 排查

以下是一些可能导致此 RabbitMQ 客户端或任何其他 RabbitMQ 客户端中的套接字读取或写入失败的常见场景 1.错过(客户端)心跳 第一个常见原因是RabbitMQ 检测到心跳丢失。发生这种情况时,RabbitMQ 将添加一个有关它的日志条目,然…

centos 7部署Mysql8.0主从

Mysql官网中关于部署主从的网址 环境准备: 搭建虚拟机和安装Mysql之前的文章中已经涉及,在此不再赘述。 主从IPMysql账号密码主192.168.213.4root/Root1234!从192.168.213.5root/Root1234! 1、主数据库设置 配置my.cnf 一般存放于/etc/。 主从配…

AI时代产品经理升级之道:ChatGPT让产品经理插上翅膀

文章目录 一、ChatGPT简介二、ChatGPT在产品经理工作中的应用1. 快速获取用户反馈2. 智能分析竞品3. 智能推荐产品4.分析市场趋势5.优化产品功能 三、总结与展望《AI时代产品经理升级之道:ChatGPT让产品经理插上翅膀》亮点内容简介目录作者简介获取方式 随着人工智能…

viple进阶1:打印星号

(1)题目:打印星号 请观察下图,使用viple编程实现 (2)设计与实现 第1种方法:行打印 利用行打印活动打印完数据后会自动换行特性 首先打印第一行,一颗星可以是字符类型&#xff0c…

python 之 字符串的相关知识

文章目录 字符串的创建基本操作字符串方法格式化字符串字符串不可变性编码和解码字符串方法详细介绍字符串方法列表1. len()2. 大小写转换方法3. 删除空白字符的方法4. 查找子字符串的方法5. 替换子字符串的方法6. 分割和连接字符串的方法7. 校验字符串内容的方法 格式化详细介…

C++——搜索二叉树

作者:几冬雪来 时间:2023年11月7日 内容:C的搜索二叉树讲解 目录 前言: 什么是搜索二叉树: 搜索二叉树的增删查改: 搜索二叉树的定义初始化: 搜索二叉树增操作: 搜索二叉树找…

蓝桥杯算法竞赛系列第十章·nSum问题的代码框架

你好,我是安然无虞。 文章目录 一、两数之和变形题 二、三数之和三、四数之和 首先,何为nSum问题呢? nSum问题其实就是给你一个数组nums和一个目标和target,让我们从nums数组中选择n个数,使得这些数字之和等于target。…

Flink集群的搭建

1、Flink独立集群模式 1、首先Flink的独立集群模式是不依赖于Hadoop集群。 2、上传压缩包,配置环境: 1、解压: tar -zxvf flink-1.15.2-bin-scala_2.12.tgz2、配置环境变量:vim /etc/profileexport FLINK_HOME/usr/local/soft/fl…

C++深度优先搜索(DFS)算法的应用:树中可以形成回文的路径数

本文涉及知识点 深度优先搜索(DFS) 状态压缩 题目 给你一棵 树(即,一个连通、无向且无环的图),根 节点为 0 ,由编号从 0 到 n - 1 的 n 个节点组成。这棵树用一个长度为 n 、下标从 0 开始的数组 parent 表示&#…

3.2-Docker Image概述

常用docker命令: 查看docker image有哪些 docker image ls Image的获取方式

亚马逊云科技产品测评』活动征文|通过使用Amazon Neptune来预测电影类型初体验

文章目录 福利来袭Amazon Neptune什么是图数据库为什么要使用图数据库什么是Amazon NeptuneNeptune 的特点 快速入门环境搭建notebook 图神经网络快速构建加载数据配置端点Gremlin 查询清理 删除环境S3 存储桶删除 授权声明:本篇文章授权活动官方亚马逊云科技文章转…

jstat虚拟机统计信息监控工具

jstat虚拟机统计信息监控工具 1、jstat(JVM Statistics Monitorning Tool) 用于监控虚拟机各种运行状态信息的命令行工具。 它可以显示本地或远程虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行数据,它是运行期定位虚拟机 性能问题…

Lenovo联想IdeaPad 15 ALC7(82R4)2022款笔记本原装出厂Windows11预装系统镜像

下载链接:https://pan.baidu.com/s/1Pr2G42Sz1LKzgF8OcEBkPQ?pwd5ms2 提取码:5ms2 系统自带所有驱动、出厂主题壁纸、系统属性专属LOGO标志、Office办公软件、联想电脑管家等预装程序 所需要工具:16G或以上的U盘 文件格式:…

centos7.9 postgresql 16.0 源码安装部署

postgresql 16.0 源码安装部署 环境准备 系统主机名IP地址centos7.9postgres192.168.200.56 软件准备 postgresql-16.0.tar.gz https://ftp.postgresql.org/pub/source/v16.0/postgresql-16.0.tar.gz依赖安装 yum -y install systemd-devel readline readline-devel zlib-devel…

探秘Python闭包与作用域

文章目录 闭包的定义与作用LEGB规则nonlocal与global关键字在Python的世界里,理解闭包(Closure)和作用域(Scope)是提升编程技巧和深度的一大步。这篇文章将带你深入了解闭包的神秘面纱,掌握LEGB规则,并使用nonlocal与global关键字来巧妙控制变量作用域。 闭包的定义与作…