• k8s 用Rinetd对外tomcatservice


    重新部署tomcat-service

    # tomcat-service.yaml
    
    apiVersion: v1
    kind: Service
    metadata:
      name: tomcat-service
      labels:
        app: tomcat-service
    spec:
    #  type: NodePort  注释type和nodePort即可。
      selector:
        app: tomcat-cluster
      ports:
      - port: 8000
        targetPort: 8080
    #    nodePort: 32500
    

    查看tomcat-service

    [bigcat@master k8s]$ kubectl describe service tomcat-service
    Name:              tomcat-service
    Namespace:         default
    Labels:            app=tomcat-service
    Annotations:       <none>
    Selector:          app=tomcat-cluster
    Type:              ClusterIP
    IP:                10.97.32.127
    Port:              <unset>  8000/TCP
    TargetPort:        8080/TCP
    Endpoints:         10.244.1.11:8080,10.244.2.8:8080
    Session Affinity:  None
    Events:            <none>
    

    通过curl 10.97.32.127:8000可以在master上看到tomcat返回默认页面。

    生成/usr/local/data/www-data/test/index.jsp

    <%=request.getLocalAddr()%>  # 显示对应的ip地址
    

    发现一个坑

    • node1/node2重启以后/mnt指向了/hgfs,而不是master的/usr/local/data/www-data,所以tomcat容器启动以后,webapps指向也不正确。
    • 手动设置/mnt映射 sudo mount 192.168.121.150:/usr/local/data/www-data /mnt
    • 重建tomcat deployment,这样tomcat容器内webapps才能指向正确路径

    运行curl 10.97.32.127:8000/test/index.jsp,就返回pod对应的ip地址,说明请求被发送到了不同的pod。

    安装端口转发工具Rinetd,实现service服务对外暴露

    # 下载rinetd.tar.gz,解开以后进入rinetd目录
    sed -i 's/65536/65535/g' rinetd.c   # 改端口映射范围
    sudo make & sudo make install       # 编译&安装
    
    vi /etc/rinetd.conf 加入地址映射
    ---------------------------------
    0.0.0.0 8000 10.97.32.127 8000  #
    
    # 加载conf
    rinetd -c /etc/rinetd.conf
    
    使用netstat -tulpn验证8000端口是否处于listen状态
    

    现在可以通过http://192.168.121.150:8000/test/index.jsp访问到tomcat-service了。
    不过我这里通过浏览器只能刷出一台pod的地址,用curl命令倒没有问题。

    --------------------------- 知道的更多,不知道的也更多 ---------------------------
  • 相关阅读:
    SAP 用户权限解剖
    效率极低人群的七大习惯你占了几项? 迎客
    数据库到底用不用外键 迎客
    办公室生存——与人相处的30个原则 迎客
    虚拟机 VirtualBox 迎客
    fancybox 迎客
    遥志代理服务器软件CCProxy 迎客
    JRE和JDK的区别 迎客
    小众软件 迎客
    网络推广方法汇集 迎客
  • 原文地址:https://www.cnblogs.com/mryux/p/15612720.html
Copyright © 2020-2023  润新知