vi /root/ingress/tomcat/tomcat-demo.yaml
内容
apiVersion: v1
kind: Service
metadata:
# service名称
name: tomcat
# 名称空间
namespace: default
spec:
# pod的标签
selector:
app: tomcat
release: canary
# 定义端口
ports:
- name: http-port
targetPort: 8080
port: 8080
- name: ajp-port
targetPort: 8009
port: 8009
---
apiVersion: apps/v1
kind: Deployment
metadata:
# Deployment名称
name: tomcat-deploy
# 名称空间
namespace: default
spec:
# 定义3个副本
replicas: 3
# 定义选择哪个template
selector:
matchLabels:
app: tomcat
release: canary
# 定义模板
template:
metadata:
# 定义标签
labels:
app: tomcat
release: canary
spec:
# 定义容器
containers:
- name: tomcat
image: tomcat:8.5.34-jre8-alpine
# 镜像拉取策略,本地有则使用本地镜像,不拉取
imagePullPolicy: IfNotPresent
ports:
- name: http-port
containerPort: 8080
name: ajp-port
containerPort: 8009
kubectl apply -f /root/ingress/tomcat/tomcat-demo.yaml
# 查看
kubectl get svc
kubectl get pods

vi /root/ingress/tomcat/ingress-tomcat.yaml
内容
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tomcat
namespace: default
annotations:
# # 注解信息,这里配置的是nginx类型的ingress
kubernetes.io/ingress.class: "nginx"
spec:
rules:
#主机域名
- host: tomcat.feizhou.com
http:
paths:
- path:
backend:
# tomcat.feizhou.com 路由到 名称为tomcat的service
serviceName: tomcat
servicePort: 8080
kubectl apply -f /root/ingress/tomcat/ingress-tomcat.yaml
# 查看
kubectl get Ingress

下面的ip是k8s的master节点ip
192.168.187.154 tomcat.feizhou.com
tomcat.feizhou.com:30080

我这里是基于 上面的 测试代理–tomcat服务,做TLS站点
https://tomcat.feizhou.com:30443/

我们发现,请求https,是走默认的后端服务,
在k8s的master节点操作
cd /root/ingress/tomcat
openssl genrsa -out tls.key 2048
openssl req -new -x509 -key tls.key -out tls.crt -subj /C=CN/ST=Beijing/L=Beijing/O=DevOps/CN=tomcat.feizhou.com
在k8s的master节点操作
kubectl create secret tls tomcat-ingress-secret --cert=tls.crt --key=tls.key
# 查看
kubectl get secret
# 查看详细信息
kubectl describe secret tomcat-ingress-secret

vi /root/ingress/tomcat/ingress-tomcat-tls.yaml
内容
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-tomcat-tls
namespace: default
annotations:
# 注解信息,这里配置的是nginx类型的ingress
kubernetes.io/ingress.class: "nginx"
spec:
tls:
- hosts:
- tomcat.feizhou.com
secretName: tomcat-ingress-secret
rules:
- host: tomcat.feizhou.com
http:
paths:
- path:
backend:
# tomcat.feizhou.com 路由到 名称为tomcat的service
serviceName: tomcat
servicePort: 8080
# 执行
kubectl apply -f /root/ingress/tomcat/ingress-tomcat-tls.yaml
# 查看
kubectl get Ingress

https://tomcat.feizhou.com:30443/
