最新kube-batch编译、部署、运行无坑教程

背景:

网上看了许多教程,都有坑,用官方的办法部署也不行,官方只说了用最新的helm,但是最新的helm已经不支持它了,没辙,自己研究了下kube-batch底层原理后总结了一套部署方法;

注意: 官方的一些yaml文件接口已经过期了(低版本k8s可以用,高版本接口没法用),helm也不能用了,所以不要用官方的yaml文件部署,直接用以下我提供的即可;

部署条件:

笔者使用的是kubernetes 1.18 + kube-batch 0.5
kubernetes 1.13以下版本可以用官方的方式或yaml文件部署(部署步骤和我下文所述一致,仅接口不同)

步骤:

一、下载

git clone -b release-0.5 https://github.com/kubernetes-sigs/kube-batch

二、创建CRD

cd kube-batch
# 先安装crds
cd config/crds
kubectl apply -f . -n kube-system
cd ..
# 安装默认的quue
cd config/queue
kubectl apply -f . -n kube-system

三、分配权限

保存以下内容为rbac.yaml,执行kubectl apply -f rbac.yaml -n kube-system

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: default-sa-admin
subjects:
  - kind: ServiceAccount
    name: default
    namespace: kube-system
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io

四、创建配置文件

保存以下内容为config.yaml,执行kubectl apply -f config.yaml -n kube-system

apiVersion: v1
data:
  kube-batch-conf.yaml: |-
    actions: "allocate, backfill"
    tiers:
    - plugins:
      - name: gang
      - name: priority
    - plugins:
      - name: drf
      - name: predicates
      - name: proportion
      - name: nodeorder
kind: ConfigMap
metadata:
  name: kube-batch-config
  namespace: kube-system

五、启动kube-batch

保存以下内容为deploy.yaml,执行kubectl apply -f deploy.yaml -n kube-system

apiVersion: app/v1
kind: Deployment
metadata:
  labels:
    app: kube-batch
  name: kube-batch
  namespace: kube-system
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: kube-batch
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: kube-batch
    spec:
      containers:
      - args:
        - --logtostderr
        - --v
        - "3"
        - --scheduler-conf=/etc/kube-batch/kube-batch-conf.yaml
        image: kube-batch/kube-batch:v0.5
        imagePullPolicy: IfNotPresent
        name: kube-batch
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        resources:
          limits:
            cpu: "2"
            memory: 2Gi
          requests:
            cpu: "2"
            memory: 2Gi
        securityContext:
          capabilities: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/kube-batch/kube-batch-conf.yaml
          name: config
          subPath: kube-batch-conf.yaml
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          defaultMode: 256
          name: kube-batch-config
          optional: false
        name: config
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: kube-batch
  name: kube-batch
  namespace: kube-system
spec:
  clusterIP: None
  ports:
  - name: http
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: kube-batch
  sessionAffinity: None
  type: ClusterIP

六、测试

保存以下内容为job.yaml,执行kubectl apply -f job.yaml

apiVersion: batch/v1
kind: Job
metadata:
  name: qj-1
spec:
  backoffLimit: 6
  completions: 6
  parallelism: 6
  template:
    metadata:
      annotations:
        scheduling.k8s.io/group-name: qj-1
    spec:
      containers:
      - image: busybox
        imagePullPolicy: IfNotPresent
        name: busybox
        resources:
          requests:
            cpu: "1"
      restartPolicy: Never
      schedulerName: kube-batch
---
apiVersion: scheduling.incubator.k8s.io/v1alpha1
kind: PodGroup
metadata:
  name: qj-1
spec:
  minMember: 6

执行kubectl get pods查看完成状态

参考文献:
https://izsk.me/2021/03/17/Kubernetes-kubebatch-install/
https://www.cnblogs.com/shix0909/p/13280261.html
https://github.com/kubernetes-sigs/kube-batch/tree/release-0.5/deployment/kube-batch/templates

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

THMAIL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值