最近研究了kebernates的弹性计算HPA,可以根据CPU和Memory的阈值设定弹出pod的数量。HPA研究过后,组内建议是否可以将presto部署到kubernates集群上,于是便开始着手部署presto到kubernates。
一 presto镜像打包
镜像打包我分开了coordinate和worker两个镜像
coordinate镜像打包:
- 打包presto
首先找一个presto的部署包,我之前在测试环境部署了一个presto 0.220,1个master(主节点也充当worker),3个worker节点。拿过来修改好etc下的配置。这里我配置了两个hive的链接,hive2指向生产环境,hive1指向测试环境
配置好config,这里的discover uri要注意,presto-coordinator-service这个域名地址是kubernates启动service的name。
coordinator=true
node-scheduler.include-coordinator=true
http-server.http.port=8099
query.max-memory=25GB
query.max-memory-per-node=2GB
query.max-total-memory-per-node=4GB
discovery-server.enabled=true
discovery.uri=http://presto-coordinator-service:8099 //这里的discover uri要注意,presto-coordinator-service这个域名地址是kubernates启动service的name
修改node.properties的data目录,这个地址是打包后镜像中的地址,需要新建的
node.environment=staging
node.data-dir=/opt/presto/data //这个地址是打包后镜像中的地址,需要新建的
将presto-server-0.220打压缩包
tar -zcvf presto-server-0.220.tar.gz presto-server-0.220
- 编写Dockerfile
FROM python //presto启动需要python环境
MAINTAINER 682556
RUN useradd --create-home --no-log-init --shell /bin/bash hive //添加hive用户
RUN adduser hive sudo
RUN mkdir -p /opt //创建目录
RUN mkdir -p /opt/presto/data //创建presto的data目录,对应presto的node.config文件中的地址
ADD java-1.8.0-openjdk-1.8.0.232.b09-0.el8_0.x86_64 /opt/jdk //打包jdk环境
ADD presto-server-0.220.tar.gz /opt //打包presto启动包
ADD whiletrue.sh /opt/rcommand.sh //这个脚本请看下面的介绍
ENV PRESTO_HOME /opt/presto-server-0.220 //设置presto home
ENV JAVA_HOME /opt/jdk //设置jdk home
ENV PATH $PATH:$JAVA_HOME/bin //设置环境变量
EXPOSE 8099
RUN chmod -R 777 /opt
USER hive //切换hive用户,必须。因为要访问hdfs必须要有hdfs读取的权限,hive用户有权限访问hdfs,所以用hive用户来启动presto
ENTRYPOINT ["/opt/rcommand.sh"] //执行启动脚本
启动脚本whiletrue.sh。在打包测试的时候,pod启动完,presto并没有启动成功,排查了很多原因,排除presto启动失败的原因,最终确定原因。kubernate的pod内如果要保持程序启动状态,必须维持session会话的等待,不能断开。这里我想了个简单的办法,就是执行启动presto脚本之后,让当前session sleep等待。(待完善)
#! /bin/bash
i=1
while ((i<100))
do
if((i<2)); then
/opt/presto-server-0.220/bin/launcher start
pwd;
else
sleep 10000000000
fi
let i++
done
- 打包镜像,这里我之前打过presto-coordinator镜像了,现在打个presto-coordinator1镜像,看下过程,后面还是用presto-coordinator镜像
打镜像标签
docker tag presto-worker:latest 10.38.150.64:8090/library/presto-coordinator
查看镜像
上传镜像到Harbor仓库(Harbor仓库参考前面的文章)
docker push 10.38.150.64:8090/library/presto-coordinator:latest
查看Harbor仓库镜像,coordinator镜像打包完成
worker镜像打包
修改presto-server-0.220文件夹下的config配置,去掉coordinator的配置,其他操作和打包coorinator镜像相同,完成worker镜像打包,并上传到Harbor
coordinator=false
http-server.http.port=8099
query.max-memory=25GB
query.max-memory-per-node=2GB
discovery.uri=http://presto-coordinator-service:8099
二 kubernate启动presto
首先将presto的coordinator镜像和worker镜像拉到本地
docker pull 10.38.150.64:8090/library/presto-coordinator:latest
docker pull 10.38.150.64:8090/library/presto-worker:latest
- 编写coorinator pod脚本
apiVersion: apps/v1
kind: Deployment
metadata:
name: presto-coordinator-service
spec:
replicas: 1
selector:
matchLabels:
app: presto-coordinator-service
template:
metadata:
labels:
app: presto-coordinator-service
spec:
containers:
- name: presto-coordinator-service
image: 10.38.150.64:8090/library/presto-coordinator:latest
ports:
- containerPort: 8099
- 编写coordinator service脚本,sevice的name和pod的name尽量保持一致,否则可能出现pod识别不了的问题。这里的service name presto-coordinator-service就是对应上面presto的discover url
apiVersion: v1
kind: Service
metadata:
name: presto-coordinator-service
labels:
name: presto-coordinator-service
spec:
type: NodePort
sessionAffinity: ClientIP
ports:
- port: 8099
name: presto-coordinator-service
targetPort: 8099
protocol: TCP
nodePort: 30012
selector:
app: presto-coordinator-service
- 编写worker pod脚本,设置pod的resouces资源,配合后面的HPA弹性计算
apiVersion: apps/v1
kind: Deployment
metadata:
name: presto-worker
spec:
replicas: 2
selector:
matchLabels:
app: presto-worker
template:
metadata:
labels:
app: presto-worker
spec:
containers:
- name: presto-worker
image: 10.38.150.64:8090/library/presto-worker:latest
ports:
- containerPort: 8099
resources:
requests:
cpu: 5000m
memory: 3000Mi
limits:
cpu: 8000m
memory: 3000Mi
- 启动presto
按顺序启动coorinator pod, coordinator service, worker pod
kubectl apply -f presto-deploy.yaml
kubectl apply -f presto-svc.yaml
kubectl apply -f presto-worker-deploy.yaml
查看启动的pod和service
访问presto ui
这里为什么显示两个worker呢,不是主节点也充当worker了嘛,应该是三个worker。确实,按照配置应该是三台,但是博主的测试环境有一台node k8node1.wux.chin.seagate.com的网络存在问题,导致presto coordinator探活的时候链接不到这台,所以只显示了2个worker。我尝试将presto-worker扩展到3台,k8node2.wux.chin.seagate.com节点也加进来了,再看presto ui确实增加了,说明启动没有问题
kubectl scale deployment presto-worker --replicas=3
- 测试presto查询