导语:希望设计一个job,首次重启后再执行。
思路是通过判断/proc/uptime的时间来判断是否为开机。为了确保k8s正常运行,大致设置了15分钟。因为重启之前进行下载解压安装,肯定超过半小时。等reboot之后,job的策略会再次运行。并让其他job等待这个job执行完毕,来夯住整个流程。
关键为wait-for-reboot这个initcontainer
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: ops-verify-install-role
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
- apiGroups: ["extensions", "apps"]
resources: ["deployments"]
verbs: ["get", "watch", "list", "patch"]
- apiGroups: ["batch","","apps"]
resources: ["jobs"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ops-verify-install-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: ops-verify-install-role
subjects:
- kind: ServiceAccount
name: ops-verify-install-operator
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: ops-verify-install-operator
---
apiVersion: batch/v1
kind: Job
metadata:
name: ops-verify-install
labels:
job-name: ops-verify-install
k8s-med-type: job
spec:
template:
metadata:
labels:
job-name: ops-verify-install
spec:
serviceAccountName: ops-verify-install-operator
initContainers:
- name: wait-for-mysql
command: ['sh', '-c', "until nc -w 3 -zv mysql 3306 ; do echo waiting for mydb; sleep 5; done"]
image: harbor.deepwise.com/base/busybox:stable-wait-for
- name: wait-for-aiserverconfig-migration
image: harbor.deepwise.com/base/k8s-wait-for:v1.3
args:
- "job"
- "aiserverconfig-migration"
- name: wait-for-aiserver-migration
image: harbor.deepwise.com/base/k8s-wait-for:v1.3
args:
- "job"
- "aiserver-migration"
- name: wait-for-platform-migration
image: harbor.deepwise.com/base/k8s-wait-for:v1.3
args:
- "job"
- "platform-migration"
- name: wait-for-pacsserver-migration
image: harbor.deepwise.com/base/k8s-wait-for:v1.3
args:
- "job"
- "pacsserver-migration"
- name: wait-for-lung-code
image: harbor.deepwise.com/base/k8s-wait-for:v1.3
args:
- "job"
- "lung-code-migration"
- name: wait-for-reboot
image: harbor.deepwise.com/base/busybox:stable-wait-for
command:
- "sh"
- "-c"
- >
uptime_seconds=$(awk '{print int($1)}' /proc/uptime);
echo uptime_seconds $uptime_seconds ;
threshold=900;
if [ "$uptime_seconds" -lt "$threshold" ]; then
echo "刚重启过";
# Replace the following command with your actual task command
else
echo "开机太久了,不触发。直接夯住等重启";
tail -f /dev/null ;
fi
containers:
- name: ops-verify-install
image: harbor.deepwise.com/base/busybox:storescu
command: ["sh","-c","curl http://10.10.3.162/xujiamin/jenkins_deploy/-/raw/master/scripts/ops_verify_install/health_check.sh?inline=false |sh && echo ' 执行激活命令并重启应用' |tee -a /opt/ops_verify_install.log && curl -o /opt/${MY_NODE_IP}_license_file.lic http://10.10.3.162/xujiamin/jenkins_deploy/-/raw/master/tools/${MY_NODE_IP}_license_file.lic && curl http://10.10.3.162/xujiamin/jenkins_deploy/-/raw/master/scripts/ops_verify_install/active_license.sh?inline=false |sh && sleep 15 && echo ' 健康检查后再推送镜像' |tee -a /opt/ops_verify_install.log && curl http://10.10.3.162/xujiamin/jenkins_deploy/-/raw/master/scripts/ops_verify_install/health_check.sh?inline=false |sh && echo ' 健康检查结束' |tee -a /opt/ops_verify_install.log "]
env:
# - name: TZ
# value: Asia/Shanghai
- name: TZ
value: CST-8
- name: MY_NODE_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
volumeMounts:
- name: ops-verify-install-storage
mountPath: /opt/
- name: lt-config
mountPath: /etc/localtime
- name: tz-config
mountPath: /etc/timezone
- name: tools
mountPath: /opt/bin
readOnly: true # 设置为只读
restartPolicy: OnFailure
volumes:
- name: ops-verify-install-storage
hostPath:
path: /opt
- name: lt-config
hostPath:
path: /etc/localtime
- name: tz-config
hostPath:
path: /etc/timezone
- name: tools
hostPath:
path: /usr/bin
type: ''
配合shutdown命令使用

172

被折叠的 条评论
为什么被折叠?



