kubernetes集群编排——k8s调度

news/2024/7/4 7:46:12 标签: kubernetes, 容器, 云原生

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.niftyadmin.cn/n/5160781.html

相关文章

SpringCloudAlibaba——Nacos

Nacos是服务注册中心服务配置中心。替换了以前的EurekaConfigBus。 1.Nacos作为服务注册中心 Nacos支持AP和CP模式的转换。 2.Nacos作为服务配置中心 服务要配置两个yml文件,bootstrap.yml和application.yml。因为Nacos同springcloud-config一样,在项…

2023-11-07 android 编译的时候出现 unused variable ‘temp0‘ [-Werror,-Wunused-variable]

一、android 编译的时候出现 unused variable temp0 [-Werror,-Wunused-variable] 二、解决方法:在android.mk里面添加 LOCAL_CFLAGS -Wno-unused-parameter -Wno-unused-variable 三、解释 -Woption 让编译器给出option指定的编译警告,常用的一些如…

美团加大了对AI大模型领域的投入!

近年来,美团一直在大模型AI领域进行大胆的投资。这个领域涉及到利用深度学习、自然语言处理和计算机视觉等技术; 开发出更加智能和高效的系统,从而提高美团的各项服务。美团相信,通过在大模型AI领域的投资,可以为用户…

Java之SpringCloud Alibaba【八】【Spring Cloud微服务Gateway整合sentinel限流】

一、Gateway整合sentinel限流 网关作为内部系统外的一层屏障,对内起到-定的保护作用&#xff0c;限流便是其中之- - .网关层的限流可以简单地针对不同路由进行限流,也可针对业务的接口进行限流,或者根据接口的特征分组限流。 1、添加依赖 <dependency><groupId>c…

爬取Elastic Stack采集的Nginx内容

以下是一个简单的Go语言爬虫程序&#xff0c;用于爬取Elastic Stack采集的Nginx内容。请注意&#xff0c;这只是一个基本的示例&#xff0c;实际使用时可能需要根据具体情况进行修改和扩展。 package mainimport ("fmt""net/http""io/ioutil" )…

文件包含漏洞培训

CTF介绍 MISC(Miscellaneous)类型,即安全杂项,题目或涉及流量分析、电子取证、人肉搜索、数据分析等等。CRYPTO(Cryptography)类型,即密码学,题目考察各种加解密技术,包括古典加密技术、现代加密技术甚至出题者自创加密技术。PWN类型,PWN在黑客俚语中代表着攻破、取得权限…

Socks5代理怎么样?安全性高吗?

Socks5代理IP的安全性取决于多个因素&#xff0c;包括代理服务器的信任度、代理提供商的可靠性以及你在使用代理时的需要注意一些动作。 下面分享一些关于Socks5代理IP安全性的重要考虑因素&#xff1a; 1. 代理服务器的信任度&#xff1a;使用代理时&#xff0c;您要确保选择信…

RK3588平台开发系列讲解(显示篇)MIPI 屏幕驱动调试

🚀返回专栏总目录 文章目录 一、背光驱动1.1、背光 PWM 节点设置1.2、backlight 节点设置二、屏幕初始化序列发送时序参数设置2.1、设备树下 DSI 节点编写2.2、DSI 的 panel 子节点编写沉淀、分享、成长,让自己和他人都能有所收获!😄 📢 调试 MIPI 屏幕主要有三部分内容…