本文主要是介绍k8s 创建job 执行oc命令 删除/操作宿主机内pod,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- 制作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/clockRUN 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/bashset -xif [ -f "/host/bin/oc_ori" ]; thenkubectl=/host/bin/oc_ori
elsekubectl=/host/bin/oc
fifunction check_kubectl() {echo "Info:check whether kubectl exists"for i in {1..20}; doif [ -f "$kubectl" ]; then return 0; else sleep10; fidoneecho "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-jobnamespace: cl-baseannotations:"helm.sh/hook": post-install,post-upgrade"helm.sh/hook-weight": "90""helm.sh/hook-delete-policy": before-hook-creation
spec:backoffLimit: 6completions: 1parallelism: 1template:metadata:name: upgrade-jobspec:serviceAccountName: cl-base-adminnodeSelector:nodeType: controllercontainers:- image: os-harbor-svc.default.svc.cloudos:443/helm/dbs/init-job:{{ .Values.initImage.tag }}imagePullPolicy: Alwayscommand:- "/bin/bash"args:- "/opt/upgrade_delete_pod.sh"name: upgrade-jobresources:limits:cpu: 4memory: 8192Mirequests:cpu: 2memory: 4096MiterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- name: tz-configmountPath: /etc/localtime- name: host-binmountPath: /host/bin- name: host-kube-configmountPath: /root/.kubednsPolicy: ClusterFirstrestartPolicy: NeverschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30volumes:- name: tz-confighostPath:path: /etc/localtime- name: host-binhostPath:path: /usr/bin- name: host-kube-confighostPath:path: /root/.kube/
这篇关于k8s 创建job 执行oc命令 删除/操作宿主机内pod的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!