k8s patch测试

1.编写patch.sh,下文件为yaml 文件模板


# 用户名
username=bqadm
# 是否挂载可写目录
iswrite="true"


container_name=$(kubectl -n bigquant get $(kubectl get deployment -l  username=${username} -n bigquant -oname) -o jsonpath='{.spec.template.spec.containers[0].name}')

deployment_name=$(kubectl get deployment -l  username=${username} -n bigquant -oname)

if [[ ${iswrite} -eq "true" ]];then
json_str='{"spec":{"template":{"spec":{"containers":[{"name":"'"${container_name}"'","volumeMounts":[{"mountPath":"/data/readonly","name":"fullgoaldata","subPath":"readonly","readOnly":true},{"mountPath":"/data/readwrite","name":"fullgoaldata","subPath":"readwrite"}]}],"volumes":[{"hostPath":{"path":"/var/app/data/bigquant/fullgoal_finance_engineer_platfrom"},"name":"fullgoaldata"}]}}}}'
else
json_str='{"spec":{"template":{"spec":{"containers":[{"name":"'"${container_name}"'","volumeMounts":[{"mountPath":"/data/readonly","name":"fullgoaldata","subPath":"readonly","readOnly":true}]}],"volumes":[{"hostPath":{"path":"/var/app/data/bigquant/fullgoal_finance_engineer_platfrom"},"name":"fullgoaldata"}]}}}}'
fi

kubectl -n bigquant patch ${deployment_name} -p ${json_str}

对应目录:
``

  • Aistudio 的pod目录
    • 只读: /data/readonly
    • 读写: /data/readwrite
  • beegfs 上对应的目录
    • 只读: /var/app/data/bigquant/fullgoal_finance_engineer_platfrom/readonly
    • 读写: /var/app/data/bigquant/fullgoal_finance_engineer_platfrom/readwrite

使用时请将对应的文件拷贝到beegfs 的目录中去;

2. k8s 1.25版本可以直接使用yaml文件进行patch

点击查看代码
spec:
  template:
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80

        volumeMounts:
        - mountPath: /var/readonly
          name: test1
          subPath: readonly
          readOnly: true
        - mountPath: /var/readwrite
          name: test1
          subPath: readwrite
      volumes:
      - hostPath:
          path: /test
        name: test1
posted @ 2023-12-29 14:30  坚强的小蚂蚁  阅读(66)  评论(0编辑  收藏  举报