Rancher部署K8s以及编排springboot项目

久未见 提交于 2020-07-29 03:03:55

rancher安装k8s集群

参考https://docs.rancher.cn/rancher2x/quick-start.html#_3-%E5%AE%89%E8%A3%85rancher

预计耗时: 5分钟

springboot打包镜像,并提交至私服镜像仓库

Dockerfile

FROM openjdk:8-jdk-alpine
# 复制打包完成后的jar文件到/opt目录下
WORKDIR /opt/
COPY ./ruoyi-sys.jar /opt/ruoyi-sys.jar
# /data设为环境变量
ENV DATAPATH /tmp
# 挂载/data目录到主机
VOLUME $DATAPATH
EXPOSE 8087
# 启动容器时执行
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-XX:-PrintGCDetails","-XX:-PrintGCTimeStamps","-XX:-HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/var/logs/dump/oom_dump.dump","-Xloggc:/var/logs/jvm/app.log","-Dfile.encoding=UTF8","-Duser.timezone=GMT+08","-XX:CMSInitiatingOccupancyFraction=90","-XX:MaxGCPauseMillis=200","-XX:StringTableSize=20000","-XX:+UseG1GC","-Xss256k","-Xmx1024m","-Xms512m","-jar","/opt/ruoyi-sys.jar"]

生成镜像

docker build -t ruoyi-sys .

docker tag 0cb3874cd22c 172.18.0.57:5000/ruoyi-sys:v1

docker push 172.18.0.57:5000/ruoyi-sys:v1

rancher编排springboot服务

在控制台点击Deploy

访问应用

手动部署服务

在用户目录新建./kube/config文件 拷贝rancher控制台的config文件到./kube/config

这样就能在宿主机本地用kubectl访问rancher的k8s集群了

kubectl --kubeconfig /home/k8s/.kube/config get pods

新建springboot应用k8s部署文件k8s-deploy.yaml

# 以Deployment部署Pod
apiVersion: apps/v1
kind: Deployment
metadata: 
  name: ruoyi-hospital-triage
spec: 
  selector: 
    matchLabels:
      app: ruoyi-hospital-triage
  replicas: 1
  template: 
    metadata:
      labels:
        app: ruoyi-hospital-triage
    spec: 
      containers: 
      - name: ruoyi-hospital-triage
        image: 172.18.0.57:5000/ruoyi-hospital-triage:latest
        ports:
        - containerPort: 8092
---
# 创建Pod的Service
apiVersion: v1
kind: Service
metadata:
  name: ruoyi-hospital-triage
spec: 
  ports: 
  - port: 80
    protocol: TCP
    targetPort: 8092
  selector:
    app: ruoyi-hospital-triage

创建k8s-deploy.sh

kubectl --kubeconfig /home/k8s/.kube/config delete -f ./k8s-deploy.yaml
kubectl --kubeconfig /home/k8s/.kube/config apply -f  ./k8s-deploy.yaml
echo "k8s deploy success!"

运行k8s-depoly.sh

issues

通过{NodeIp}:30000 打不开应用首页

修改server.servlet.context-path=/

# 开发环境配置
server:
  # 服务器的HTTP端口,默认为80
  port: 8087
  servlet:
    # 应用的访问路径
    context-path: /

验证码字体获取错误

openjdk缺少相关配置,修改Dockerfile,增加字体配置

宿主机运行kubectl

kubectl --kubeconfig /home/k8s/.kube/config get pods -o wide

参考资料

https://docs.rancher.cn/rancher2x/quick-start.html

https://kuboard.cn/learning/k8s-practice/ocp/eureka-server.html

https://www.cnblogs.com/famary/p/11329236.html

https://docs.rancher.cn/rancher2x/installation/#_2-2-%E6%96%B9%E6%A1%88%E4%BA%8C%E3%80%81%E5%85%A8%E5%B1%80nginx-http-ingress-http-rancher

https://rancher.com/docs/rancher/v2.x/en/cluster-admin/cluster-access/kubectl/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!