为k8s部署第二个调度器
为k8s部署第二个调度器环境配置下载k8s源码并编译制作镜像部署deployment查看pod状态纠错结束环境配置ubuntu:16.04docker:20.10.7golang:1.17.8kubernetes:1.23.4环境的搭建就不多赘述了,可以参照网上的资源自行搭建。下载k8s源码并编译cd ~/go#环境变量GOPATH=$HOME/gogit clone https://github
为k8s部署第二个调度器
环境配置
- ubuntu:16.04
- docker:20.10.7
- golang:1.17.8
- kubernetes:1.23.4
环境的搭建就不多赘述了,可以参照网上的资源自行搭建。
下载k8s源码并编译
cd ~/go#环境变量GOPATH=$HOME/go
git clone https://github.com/kubernetes/kubernetes.git
下载完成后,进入kubernetes
文件夹编译kube-scheduler
:
cd kubernetes/
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make WHAT=cmd/kube-scheduler/
这里需要注意的是,CGO_ENABLED=0
必须要有,后面两个选项可有可无,这是为了让项目编译时,把依赖库文件也链接进可执行文件中,如果不指定这个选项,后面启动容器时会失败,pod
会一直处于CrashLoopBackOff
的状态。
WHAT=cmd/kube-scheduler/
告诉编译器只编译kube-scheduler
模块,生成的文件在kubernetes/_output/local/bin/linux/amd64/
路径下。
制作镜像
创建一个文件夹,并添加如下两个文件:
其中Dockerfile
的内容为:
FROM busybox
ADD ./kube-scheduler /usr/local/bin/kube-scheduler
如果后面运行调度器时,遇到如下问题:
可以在文件中加一句:
FROM busybox
ADD ./kube-scheduler /usr/local/bin/kube-scheduler
RUN chmod a+x /usr/local/bin/kube-scheduler
kube-scheduler
文件即为之前编译生成的可执行文件,从原本的路径复制过来。
在两个文件所在的目录下,执行镜像构建命令:
docker build -t XXX/kube-scheduler:1.0 .
XXX
改成你的docker仓库名。
推送镜像:
docker push XXX/kube-scheduler:1.0
部署deployment
.yaml
文件内容:
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-scheduler
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: my-scheduler-as-kube-scheduler
subjects:
- kind: ServiceAccount
name: my-scheduler
namespace: kube-system
roleRef:
kind: ClusterRole
name: system:kube-scheduler
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ConfigMap
metadata:
name: my-scheduler-config
namespace: kube-system
data:
my-scheduler-config.yaml: |
apiVersion: kubescheduler.config.k8s.io/v1beta2
kind: KubeSchedulerConfiguration
profiles:
- schedulerName: my-scheduler
leaderElection:
leaderElect: false
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: my-scheduler-as-volume-scheduler
subjects:
- kind: ServiceAccount
name: my-scheduler
namespace: kube-system
roleRef:
kind: ClusterRole
name: system:volume-scheduler
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
component: scheduler
tier: control-plane
name: my-scheduler
namespace: kube-system
spec:
selector:
matchLabels:
component: scheduler
tier: control-plane
replicas: 1
template:
metadata:
labels:
component: scheduler
tier: control-plane
version: second
spec:
serviceAccountName: my-scheduler
containers:
- command:
- /usr/local/bin/kube-scheduler
- --config=/etc/kubernetes/my-scheduler/my-scheduler-config.yaml
image: XXX/my-kube-scheduler:1.0 #修改成你的镜像名
livenessProbe:
httpGet:
path: /healthz
port: 10259
scheme: HTTPS
initialDelaySeconds: 15
name: kube-second-scheduler
readinessProbe:
httpGet:
path: /healthz
port: 10259
scheme: HTTPS
resources:
requests:
cpu: '0.1'
securityContext:
privileged: false
volumeMounts:
- name: config-volume
mountPath: /etc/kubernetes/my-scheduler
hostNetwork: false
hostPID: false
volumes:
- name: config-volume
configMap:
name: my-scheduler-config
注意修改文件中加注释的部分,改成你的镜像名。
执行如下命令:
kubectl create -f my-scheduler.yaml
查看pod状态
kubectl get pods -n kube-system
名为my-scheduler-xxx-xxx
的pod
运行正常。
纠错
有两个命令比较有用:
kubectl describe pod PODNAME#输出pod的详细信息
kubectl logs -f PODNAME#输出pod的日志
对报错信息积极百度,总能找到解决办法。
结束
祝各位顺利。
更多推荐
所有评论(0)