KEP-3633 alternative
Overview
KEP-3633 is great and now under developing, but I need it NOW.
Luckily, it's behavior can mimic with MutatingAdmissionWebhook.
So, I implement this according to KEP.
Roadmap and statuses
- Implement webhook
- append
.spec.affinity.podAffinity.required...Execution
- append
.spec.affinity.podAffinity.preferred...Execution
- append
.spec.affinity.podAntiAffinity.required...Execution
- append
.spec.affinity.podAntiAffinity.preferred...Execution
- Build and publish container image
- published to
ghcr.io/10hin/kep3633alt:latest
- Write installation manifest
- Kustomize manifest (depends on cert-manager to provision webhook certificates)
- Helm chart without dependencies to cert-manager
Install
Use helm
with adding our repository:
helm repo add kep3633alt https://10hin.github.io/kep-3633-alt
helm repo update
helm upgrade -i -n kube-system kep3633alt kep3633alt/kep3633alt
Or without it:
helm upgrade -i -n kube-system kep3633alt kep3633alt --repo https://10hin.github.io/kep-3633-alt
Chart source is here.
Usage
After installation, deploy pods with pod affinity (or anti-affinity) configured not on spec
but on annotations
with JSON format.
If you have pod manifest (typically as pod template in deployment resource) using KEP3633 like following:
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
pod-template-hash: UNEXPECTABLEVALUE
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: nginx
topologyKey: topology.kubernetes.io/zone
matchLabelKeys:
- pod-template-hash
# ...
above manifest may invalid for now. So, you can alternate it as follows:
apiVersion: v1
kind: Pod
metadata:
annotations:
kep-3633-alt.10h.in/podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution: |
[
{
"labelSelector": {
"matchLabels": {
"app": "nginx"
}
},
"topologyKey": "topology.kubernetes.io/zone",
"matchLabelKeys": [
"pod-template-hash"
]
}
]
name: nginx
labels:
app: nginx
pod-template-hash: UNEXPECTABLEVALUE
spec:
# ...
then it applied as follows:
apiVersion: v1
kind: Pod
metadata:
annotations:
kep-3633-alt.10h.in/podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution: |
# reduced
name: nginx
labels:
app: nginx
pod-template-hash: UNEXPECTABLEVALUE
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: nginx
pod-template-hash: UNEXPECTABLEVALUE
topologyKey: topology.kubernetes.io/zone
# ...
Usecases
see KEP3633