使用KWOK拉起数千个假Node和假Pod

介绍:

KWOK 是一个工具包,能在数秒内建立一个由数千个节点组成的集群。在场景下,所有节点都是模拟的,行为与真实节点无异,因此整体方法占用的资源非常少。

安装:

官网:kwok.sigs.k8s.io/

KWOK支持两种安装方式,第一种是在现有的集群上安装,第二种是直接起一个假集群。

1. 设置变量参数

定义变量KWOK_REPO用于存储kwok的仓库地址

ini 复制代码
KWOK_REPO=kubernetes-sigs/kwok

定义变量KWOK_LATEST_RELEASE,获取当前kwok的最新版本,当然也可以将版本写死在变量中,写这篇文章的时候测试版本为v0.4.0。

ini 复制代码
KWOK_LATEST_RELEASE=$(curl "https://api.github.com/repos/${KWOK_REPO}/releases/latest" | jq -r '.tag_name')

2. 安装KWOK controller

kwok-controller是一个deployment,请求github上对应版本的kwok.yaml并部署在集群上

bash 复制代码
kubectl apply -f "https://github.com/${KWOK_REPO}/releases/download/${KWOK_LATEST_RELEASE}/kwok.yaml"

确保kwok-controller被正确启动,有可能会因为网络原因导致镜像拉取失败

3. 设置假node、pod的模拟行为

bash 复制代码
kubectl apply -f "https://github.com/${KWOK_REPO}/releases/download/${KWOK_LATEST_RELEASE}/stage-fast.yaml"

部署

1. 假节点(fake node)

在部署pod前至少需要部署一个fake node,否则无法部署fake pod。如果需要拉起多个fake node需要修改labels中的name和kubernetes.io/hostname。

yaml 复制代码
kubectl apply -f - <<EOF
apiVersion: v1
kind: Node
metadata:
  annotations:
    node.alpha.kubernetes.io/ttl: "0"
    kwok.x-k8s.io/node: fake
  labels:
    beta.kubernetes.io/arch: amd64
    beta.kubernetes.io/os: linux
    kubernetes.io/arch: amd64
    kubernetes.io/hostname: kwok-node-0
    kubernetes.io/os: linux
    kubernetes.io/role: agent
    node-role.kubernetes.io/agent: ""
    type: kwok
  name: kwok-node-0
spec:
  taints: # Avoid scheduling actual running pods to fake Node
  - effect: NoSchedule
    key: kwok.x-k8s.io/node
    value: fake
status:
  allocatable:
    cpu: 32
    memory: 256Gi
    pods: 110
  capacity:
    cpu: 32
    memory: 256Gi
    pods: 110
  nodeInfo:
    architecture: amd64
    bootID: ""
    containerRuntimeVersion: ""
    kernelVersion: ""
    kubeProxyVersion: fake
    kubeletVersion: fake
    machineID: ""
    operatingSystem: linux
    osImage: ""
    systemUUID: ""
  phase: Running
EOF

使用kubectl get no查看node节点,就可以看到我拉起的两个fake node都已经处于Ready状态了。

2. 假Pod(fake pod)

接着就可以apply这个yaml文件用于拉起多个fake pod。这个文件中设置了replicas为10,就会拉起10个fake pod,可以根据需要进行调整。

yaml 复制代码
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: fake-pod
  namespace: default
spec:
  replicas: 10
  selector:
    matchLabels:
      app: fake-pod
  template:
    metadata:
      labels:
        app: fake-pod
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: type
                operator: In
                values:
                - kwok
      # A taints was added to an automatically created Node.
      # You can remove taints of Node or add this tolerations.
      tolerations:
      - key: "kwok.x-k8s.io/node"
        operator: "Exists"
        effect: "NoSchedule"
      containers:
      - name: fake-container
        image: fake-image
EOF
相关推荐
Ai拆代码的曹操1 小时前
K8s Pod Pending 逐层排查:从 FailedScheduling 到 PVC StorageClass 不存在的实战记录
java·linux·kubernetes
L-影8 小时前
单体与微服务区别
微服务·云原生·架构
运维大师9 小时前
【K8S 运维实战】01-K8s架构深度剖析
运维·架构·kubernetes
spider_xcxc11 小时前
docker-compose.yaml 是“开发/测试环境”的利器,而 Kubernetes 配置是“生产环境”的标准。
docker·容器·kubernetes
chen_ke_hao12 小时前
K8s 高可用集群部署
java·docker·kubernetes
Geek-Chow13 小时前
Kubernetes HPA Behavior When Deployment Is Scaled to 0
云原生·容器·kubernetes
张忠琳1 天前
【kubernetes】Node Feature Discovery 0.20.0-devel 源码深度解析 — 第四卷:CLI入口、工具链与全局架构总结
云原生·容器·架构·kubernetes·nvidia
Navicat中国1 天前
开发者入门:无服务器数据库
数据库·云原生·serverless·navicat
汪汪大队u1 天前
【无标题】
运维·docker·kubernetes·prometheus
ai_coder_ai1 天前
编写自动化脚本,在自己后端服务中使用云原生Baas服务进行编码和解码相关操作
数据库·云原生·自动化