介绍:
KWOK 是一个工具包,能在数秒内建立一个由数千个节点组成的集群。在场景下,所有节点都是模拟的,行为与真实节点无异,因此整体方法占用的资源非常少。
安装:
官网:kwok.sigs.k8s.io/
KWOK支持两种安装方式,第一种是在现有的集群上安装,第二种是直接起一个假集群。
1. 设置变量参数
定义变量KWOK_REPO
用于存储kwok的仓库地址
KWOK_REPO=kubernetes-sigs/kwok
定义变量KWOK_LATEST_RELEASE
,获取当前kwok的最新版本,当然也可以将版本写死在变量中,写这篇文章的时候测试版本为v0.4.0。
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并部署在集群上
kubectl apply -f "https://github.com/${KWOK_REPO}/releases/download/${KWOK_LATEST_RELEASE}/kwok.yaml"
确保kwok-controller
被正确启动,有可能会因为网络原因导致镜像拉取失败
3. 设置假node、pod的模拟行为
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。
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,可以根据需要进行调整。
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