使用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
相关推荐
小猿姐1 天前
MySQL Top 10 热点问题 AI 运维实战:从内核诊断到云原生运维
mysql·云原生·aiops
阿里云云原生3 天前
深入内核:拆解 OpenTelemetry eBPF 探针如何优雅地“透视”多语言微服务?
云原生
java_cj3 天前
深入kube-apiserver认证机制:从Bearer Token到mTLS的完整认证链解析
linux·运维·服务器·云原生·容器·kubernetes
qq_452396233 天前
第十三篇:《K8s 安全基础:RBAC、ServiceAccount、Pod Security》
java·安全·kubernetes
睡不醒男孩0308233 天前
云原生运维实战:高并发架构下的云原生可观测性、韧性降级与自动化干预体系
数据库·kubernetes·高并发·prometheus·devops·sre·缓存调优
qq_452396233 天前
第十四篇:《K8s 网络模型与 CNI 插件(Calico、Flannel、Cilium)》
网络·kubernetes·php
Hadoop_Liang3 天前
Kubernetes 应用 HTTPS 安全访问配置实践
https·kubernetes
互联网推荐官3 天前
上海软件定制开发公司推荐:从PaaS工程化路径看D-coding的技术取舍
云原生·云计算·paas·软件开发·开发经验·上海
sbjdhjd3 天前
从零搭建企业级 CI/CD(下):Jenkins+GitLab+Harbor 全链路实战指南
git·servlet·ci/cd·云原生·云计算·gitlab·jenkins
java_cj3 天前
从0到1启动kube-apiserver:深入源码解析API Server启动全流程
docker·容器·kubernetes