Kwok
建立抽象的 node,可以模擬 pod 部署在上面
Install
安裝 mac cli
brew install kwok
Deploy kwok
in a Cluster
`kwok` in Cluster | KWOK (k8s.io)
# KWOK repository
KWOK_REPO=kubernetes-sigs/kwok
# Get latest
KWOK_LATEST_RELEASE=$(curl "https://api.github.com/repos/${KWOK_REPO}/releases/latest" | jq -r '.tag_name')
kubectl apply -f "https://github.com/${KWOK_REPO}/releases/download/${KWOK_LATEST_RELEASE}/kwok.yaml"
kubectl apply -f "https://github.com/${KWOK_REPO}/releases/download/${KWOK_LATEST_RELEASE}/stage-fast.yaml"
不太清楚為何要有第三步
如果加入第二步
但還是呈現 notReady
就算加入第三步也不行,要一開始就先設定好
Stage
node, pod 都有自己的 stage,加入 stage 的 api spec,可以模擬 node/pod 的各種過程
像是符合 selector: env=prod,其中的 Finalizers
要不一樣。
Node stages
Pending: The node is being provisioned and is not yet ready for use.
Ready: The node is ready for use and can be scheduled for pods.
Not Ready: The node is not ready for use and cannot be scheduled for pods.
Terminating: The node is being terminated and will be removed from the cluster.
Unknown: The state of the node is unknown.
Pod stages
Pending: The pod is being created and is not yet running.
Running: The pod is running and ready to accept traffic.
Succeeded: The pod has completed its execution and has exited with a zero status code.
Failed: The pod has failed to execute and has exited with a non-zero status code.
Unknown: The state of the pod is unknown.
kind: Stage
apiVersion: kwok.x-k8s.io/v1alpha1
metadata:
name: <string>
spec:
resourceRef:
apiGroup: <string>
kind: <string>
selector:
matchLabels:
<string>: <string>
matchAnnotations:
<string>: <string>
matchExpressions:
- key: <expressions-string>
operator: <string>
values:
- <string>
delay:
durationMilliseconds: <int>
durationFrom:
expressionFrom: <expressions-string>
jitterDurationMilliseconds: <int>
jitterDurationFrom:
expressionFrom: <expressions-string>
next:
statusTemplate: <string>
finalizers:
add:
- value: <string>
remove:
- value: <string>
empty: <bool>
delete: <bool>
immediateNextStage: <bool>
selector: 滿足的 pod, node 會執行下面的狀態
delay: 可以加入隨機的等待時間
next:
statusTemplate: 編寫 pod 與內部 container 的狀態
finalizers: 如何移除相關性的 (Finalizers are namespaced keys that tell Kubernetes to wait until specific conditions are met before it fully deletes resources marked for deletion.)
下面是 pod-ready 為例子
Use as node
# filename: node.yaml
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
kubectl apply -f node.yaml
node 有 taint
加入 pod
# pod.yaml
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