k8s 创建job 执行oc命令 删除/操作宿主机内pod
制作job 所使用的的容器 DockerfileFROM xxx.xxx.com/alpine:3.9COPY glibd-2.23-r3.apk /opt/glibd-2.23-r3.apkCOPY ./ssh_config /etc/ssh/COPY clock /etc/sysconfig/clockRUN echo "xxx.xxx.com/alpine/v3.9/main" >/e
·
- 制作job 所使用的的容器 Dockerfile
FROM xxx.xxx.com/alpine:3.9
COPY glibd-2.23-r3.apk /opt/glibd-2.23-r3.apk
COPY ./ssh_config /etc/ssh/
COPY clock /etc/sysconfig/clock
RUN echo "xxx.xxx.com/alpine/v3.9/main" >/etc/apk/repositories && \
echo "xxx.xxx.com/alpine/v3.9/main" >/etc/apk/repositories && \
apk add --no-cache sshpass openssh-client grep bash bash-doc bash-completion zip && \
apk --allow-untrusted --force add /opt/glibc-2.23-r3.apk && \
mkdir -p /root/.ssh && \
rm /opt/glibc-2.23-r3.apk && \
rm -rf /var/cache/apk/*
COPY config /root/.ssh
copy delete_pod.sh \
xxx.sh \
/opt/
2.删除宿主机pod脚本
#!/bin/bash
set -x
if [ -f "/host/bin/oc_ori" ]; then
kubectl=/host/bin/oc_ori
else
kubectl=/host/bin/oc
fi
function check_kubectl() {
echo "Info:check whether kubectl exists"
for i in {1..20}; do
if [ -f "$kubectl" ]; then return 0; else sleep10; fi
done
echo "failed"
return 1
}
function delete_pod() {
echo "get pod"
names=`${kubectl} get deployment -n xxxxx-base | grep -i "ssssssxxxxx" | awk '{print $1}'`
# 后续自己发挥
}
3.k8s job yaml文件
apiVersion: batch/v1
kind: Job
metadata:
name: upgrade-job
namespace: cl-base
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "90"
"helm.sh/hook-delete-policy": before-hook-creation
spec:
backoffLimit: 6
completions: 1
parallelism: 1
template:
metadata:
name: upgrade-job
spec:
serviceAccountName: cl-base-admin
nodeSelector:
nodeType: controller
containers:
- image: os-harbor-svc.default.svc.cloudos:443/helm/dbs/init-job:{{ .Values.initImage.tag }}
imagePullPolicy: Always
command:
- "/bin/bash"
args:
- "/opt/upgrade_delete_pod.sh"
name: upgrade-job
resources:
limits:
cpu: 4
memory: 8192Mi
requests:
cpu: 2
memory: 4096Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- name: tz-config
mountPath: /etc/localtime
- name: host-bin
mountPath: /host/bin
- name: host-kube-config
mountPath: /root/.kube
dnsPolicy: ClusterFirst
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: tz-config
hostPath:
path: /etc/localtime
- name: host-bin
hostPath:
path: /usr/bin
- name: host-kube-config
hostPath:
path: /root/.kube/
更多推荐
已为社区贡献3条内容
所有评论(0)