2021-12-17 10:57:23 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
2022-01-24 12:37:23 +00:00
|
|
|
VERSION="v1.21.9"
|
2021-12-17 10:57:23 +00:00
|
|
|
|
|
|
|
[ -n "$DEBUG" ] && DEBUG=1
|
2021-12-03 21:13:40 +00:00
|
|
|
|
|
|
|
# unset any AWS_DEFAULT_PROFILE as it will break aws-iam-auth
|
|
|
|
unset AWS_DEFAULT_PROFILE
|
|
|
|
|
|
|
|
nodes=$(kubectl get nodes -l node-role.kubernetes.io/control-plane -o json | jq .items[].metadata.name -r)
|
|
|
|
for node in $nodes; do
|
|
|
|
echo "Deploying node upgrade job on $node..."
|
|
|
|
|
2021-12-17 10:57:23 +00:00
|
|
|
cat <<EOF | sed -e "s/__node__/$node/g" | kubectl apply -f -
|
2021-12-03 21:13:40 +00:00
|
|
|
apiVersion: v1
|
|
|
|
kind: Pod
|
|
|
|
metadata:
|
2021-12-17 10:57:23 +00:00
|
|
|
name: kubezero-upgrade-${VERSION//.}-node-__node__
|
2021-12-03 21:13:40 +00:00
|
|
|
namespace: kube-system
|
|
|
|
labels:
|
|
|
|
app: kubezero-upgrade-node
|
|
|
|
spec:
|
|
|
|
hostNetwork: true
|
|
|
|
containers:
|
|
|
|
- name: kubezero-admin
|
2021-12-17 10:57:23 +00:00
|
|
|
image: public.ecr.aws/zero-downtime/kubezero-admin:${VERSION}
|
2021-12-03 21:13:40 +00:00
|
|
|
imagePullPolicy: Always
|
|
|
|
command: ["kubezero.sh"]
|
|
|
|
args:
|
|
|
|
- node-upgrade
|
|
|
|
env:
|
|
|
|
- name: DEBUG
|
2021-12-17 10:57:23 +00:00
|
|
|
value: "$DEBUG"
|
2021-12-03 21:13:40 +00:00
|
|
|
- name: NODE_NAME
|
|
|
|
valueFrom:
|
|
|
|
fieldRef:
|
|
|
|
fieldPath: spec.nodeName
|
|
|
|
volumeMounts:
|
|
|
|
- name: host
|
|
|
|
mountPath: /host
|
|
|
|
- name: workdir
|
|
|
|
mountPath: /tmp
|
|
|
|
securityContext:
|
|
|
|
capabilities:
|
|
|
|
add: ["SYS_CHROOT"]
|
|
|
|
volumes:
|
|
|
|
- name: host
|
|
|
|
hostPath:
|
|
|
|
path: /
|
|
|
|
type: Directory
|
|
|
|
- name: workdir
|
|
|
|
emptyDir: {}
|
|
|
|
nodeSelector:
|
|
|
|
kubernetes.io/hostname: __node__
|
|
|
|
tolerations:
|
|
|
|
- key: node-role.kubernetes.io/master
|
|
|
|
effect: NoSchedule
|
|
|
|
restartPolicy: Never
|
|
|
|
EOF
|
2021-12-17 10:57:23 +00:00
|
|
|
kubectl wait pod kubezero-upgrade-${VERSION//.}-node-$node -n kube-system --timeout 120s --for=condition=initialized 2>/dev/null
|
2021-12-03 21:13:40 +00:00
|
|
|
while true; do
|
2021-12-17 10:57:23 +00:00
|
|
|
kubectl logs kubezero-upgrade-${VERSION//.}-node-$node -n kube-system -f 2>/dev/null && break
|
2021-12-03 21:13:40 +00:00
|
|
|
sleep 3
|
|
|
|
done
|
2021-12-17 10:57:23 +00:00
|
|
|
kubectl delete pod kubezero-upgrade-${VERSION//.}-node-$node -n kube-system
|
2021-12-03 21:13:40 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "Deploying cluster upgrade job ..."
|
|
|
|
|
2021-12-17 10:57:23 +00:00
|
|
|
cat <<EOF | kubectl apply -f -
|
2021-12-03 21:13:40 +00:00
|
|
|
apiVersion: v1
|
|
|
|
kind: Pod
|
|
|
|
metadata:
|
2021-12-17 10:57:23 +00:00
|
|
|
name: kubezero-upgrade-${VERSION//.}
|
2021-12-03 21:13:40 +00:00
|
|
|
namespace: kube-system
|
|
|
|
labels:
|
|
|
|
app: kubezero-upgrade
|
|
|
|
spec:
|
|
|
|
hostNetwork: true
|
|
|
|
#hostIPC: true
|
|
|
|
#hostPID: true
|
|
|
|
containers:
|
|
|
|
- name: kubezero-admin
|
2021-12-17 10:57:23 +00:00
|
|
|
image: public.ecr.aws/zero-downtime/kubezero-admin:${VERSION}
|
2021-12-03 21:13:40 +00:00
|
|
|
imagePullPolicy: Always
|
|
|
|
command: ["kubezero.sh"]
|
|
|
|
args:
|
|
|
|
- upgrade
|
|
|
|
env:
|
|
|
|
- name: DEBUG
|
2021-12-17 10:57:23 +00:00
|
|
|
value: "$DEBUG"
|
2021-12-03 21:13:40 +00:00
|
|
|
- name: NODE_NAME
|
|
|
|
valueFrom:
|
|
|
|
fieldRef:
|
|
|
|
fieldPath: spec.nodeName
|
|
|
|
volumeMounts:
|
|
|
|
- name: host
|
|
|
|
mountPath: /host
|
|
|
|
- name: workdir
|
|
|
|
mountPath: /tmp
|
|
|
|
securityContext:
|
|
|
|
capabilities:
|
|
|
|
add: ["SYS_CHROOT"]
|
|
|
|
volumes:
|
|
|
|
- name: host
|
|
|
|
hostPath:
|
|
|
|
path: /
|
|
|
|
type: Directory
|
|
|
|
- name: workdir
|
|
|
|
emptyDir: {}
|
|
|
|
nodeSelector:
|
2021-12-17 10:57:23 +00:00
|
|
|
node-role.kubernetes.io/control-plane: ""
|
2021-12-03 21:13:40 +00:00
|
|
|
tolerations:
|
|
|
|
- key: node-role.kubernetes.io/master
|
|
|
|
effect: NoSchedule
|
|
|
|
restartPolicy: Never
|
|
|
|
EOF
|
|
|
|
|
2021-12-17 10:57:23 +00:00
|
|
|
kubectl wait pod kubezero-upgrade-${VERSION//.} -n kube-system --timeout 120s --for=condition=initialized 2>/dev/null
|
2021-12-03 21:13:40 +00:00
|
|
|
while true; do
|
2021-12-17 10:57:23 +00:00
|
|
|
kubectl logs kubezero-upgrade-${VERSION//.} -n kube-system -f 2>/dev/null && break
|
2021-12-03 21:13:40 +00:00
|
|
|
sleep 3
|
|
|
|
done
|
2021-12-17 10:57:23 +00:00
|
|
|
kubectl delete pod kubezero-upgrade-${VERSION//.} -n kube-system
|