网站首页 > 技术教程 正文
案例说明:静态页面直接访问nginx, 动态请求通过tomcat
架构图如下:
nginx服务的配置文件nginx.yaml如下:
kind: Deployment
#apiVersion: extensions/v1beta1
apiVersion: apps/v1
metadata:
labels:
app: linux66-nginx-deployment-label
name: linux66-nginx-deployment
namespace: linux66
spec:
replicas: 1
selector:
matchLabels:
app: linux66-nginx-selector
template:
metadata:
labels:
app: linux66-nginx-selector
spec:
containers:
- name: linux66-nginx-container
image: nginx
#command: ["/apps/tomcat/bin/run_tomcat.sh"]
imagePullPolicy: IfNotPresent
#imagePullPolicy: Always
ports:
- containerPort: 80
protocol: TCP
name: http
- containerPort: 443
protocol: TCP
name: https
env:
- name: "password"
value: "123456"
- name: "age"
value: "18"
# resources:
# limits:
# cpu: 2
# memory: 2Gi
# requests:
# cpu: 500m
# memory: 1Gi
---
kind: Service
apiVersion: v1
metadata:
labels:
app: linux66-nginx-service-label
name: linux66-nginx-service
namespace: linux66
spec:
type: NodePort
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
nodePort: 30006
- name: https
port: 443
protocol: TCP
targetPort: 443
nodePort: 30443
selector:
app: linux66-nginx-selector
tomcat服务的配置文件tomcat.yaml如下:
root@k8s-master:~/yaml/1202# cat tomcat.yaml
kind: Deployment
#apiVersion: extensions/v1beta1
apiVersion: apps/v1
metadata:
labels:
app: linux66-tomcat-app1-deployment-label
name: linux66-tomcat-app1-deployment
namespace: linux66
spec:
replicas: 1
selector:
matchLabels:
app: linux66-tomcat-app1-selector
template:
metadata:
labels:
app: linux66-tomcat-app1-selector
spec:
containers:
- name: linux66-tomcat-app1-container
image: tomcat:7.0.94-alpine
#command: ["/apps/tomcat/bin/run_tomcat.sh"]
imagePullPolicy: IfNotPresent
#imagePullPolicy: Always
ports:
- containerPort: 8080
protocol: TCP
name: http
env:
- name: "password"
value: "123456"
- name: "age"
value: "18"
resources:
limits:
cpu: 1
memory: "512Mi"
requests:
cpu: 500m
memory: "512Mi"
---
kind: Service
apiVersion: v1
metadata:
labels:
app: linux66-tomcat-app1-service-label
name: linux66-tomcat-app1-service
namespace: linux66
spec:
#type: NodePort
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
#nodePort: 40003
selector:
app: linux66-tomcat-app1-selector
创建namespace
kubectl create ns linux66
添加tomcat页面
root@k8s-master:~/yaml/1202# kubectl exec -it -n linux66 linux66-tomcat-app1-deployment-7946f87f8f-28r7b bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
bash-4.4# pwd
/usr/local/tomcat
bash-4.4# ls
BUILDING.txt NOTICE RUNNING.txt include native-jni-lib work
CONTRIBUTING.md README.md bin lib temp
LICENSE RELEASE-NOTES conf logs webapps
bash-4.4# cd webapps/
bash-4.4# ls
ROOT docs examples host-manager manager
bash-4.4# mkdir login
bash-4.4# ls
ROOT docs examples host-manager login manager
bash-4.4# echo "<h1>Login Web Page</h1>" >login/index.jsp
bash-4.4# exit
修改haproxy配置
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen k8s-cluster-01-6443
bind 172.31.7.188:6443
mode tcp
server k8s-master.host.com 172.31.7.2:6443 check inter 3s fall 3 rise 1
#增加如下配置,访问80的时候通过vip转到宿主机的80端口
listen k8s-linux66-nginx-80
bind 172.31.7.189:80
mode tcp
server k8s-master.host.com 172.31.7.2:30006 check inter 3s fall 3 rise 1
验证结果
修改nginx配置,访问login时跳转到tomcat服务,一般是把这部分配置打到镜像里面。
root@linux66-nginx-deployment-6bb84c7d7b-jxfnc:/# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#增加如下配置,访问login页面跳车到tomcat,地址通tomcat的svc地址,最好写全称
location /login{
proxy_pass http://linux66-tomcat-app1-service.linux66.svc.cluster.local;
}
#nginx -s reload
静态页面直接通过nginx访问
猜你喜欢
- 2024-10-10 doker容器实战分别实现nginx、tomcat、mysql
- 2024-10-10 阿里P8终于总结出:SpringBoot+Tomcat+Nginx+Netty面试题及答案
- 2024-10-10 Nginx 和 tomcat开启Gzip功能的方法
- 2024-10-10 nginx 反向代理tomcat(nginx 反向代理配置)
- 2024-10-10 nginx反向代理tomcat集群(nginx反向代理实例)
- 2024-10-10 Nginx负载均衡+Tomcat架构还不透彻?Java架构师必读书籍送给你
- 2024-10-10 服务器环境中Tomcat、Nginx和Apache有什么特点呢?
- 2024-10-10 百度T7分享:Nginx+Tomcat实现负载均衡 动静分离集群 让你年薪30w
- 2024-10-10 Nginx+Tomcat 动静分离实现负载均衡
- 2024-10-10 注意这几点,轻轻松松配置 Nginx + Tomcat 的集群和负载均衡
你 发表评论:
欢迎- 最近发表
-
- linux CentOS检查见后门程序的shell
- 网络安全工程师演示:黑客是如何使用Nmap网络扫描工具的?
- Linux中ftp服务修改默认21端口等(linux修改ftp配置文件)
- Linux系统下使用Iptables配置端口转发,运维实战收藏!
- 谈谈TCP和UDP源端口的确定(tcp和udp的端口号相同吗)
- Linux 系统 通过端口号找到对应的服务及相应安装位置
- 快速查找NAS未占用端口!Docker端口秒级排查+可视化占坑双杀技
- 【知识杂谈#2】如何查看Linux的(本地与公网)IP地址与SSH端口号
- 如何在Linux中查询 DNS 记录,这三个命令可谓是最常用、最经典的
- 【Linux系统编程】特殊进程之守护进程
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)