Files
2026-03-27 16:58:41 +08:00

96 lines
3.8 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# docs/03-03 第 5 节Tomcat + test05.jackadam.top 验证 HTTPS请按需改域名
---
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: tomcat-test05 # Deployment 名称
namespace: default # 命名空间
labels: # 标签
app: tomcat-test05 # 应用标签
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: tomcat-test05 # 与模板标签对齐
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: tomcat-test05 # 与 selector.matchLabels 对齐
spec: # Pod 规格
containers: # 容器列表
- name: tomcat # 容器名
image: tomcat:9.0 # Tomcat 镜像版本
# 官方镜像默认 webapps 在 webapps.dist整目录复制到 webapps与 Docker Compose cp -a webapps.dist/* webapps 等价)
command: # 启动命令(覆盖默认 ENTRYPOINT/CMD
- sh # 使用 shell
- -c # shell 执行模式
- | # 多行脚本(内部内容保持原样)
set -e
CATALINA_HOME=/usr/local/tomcat
mkdir -p "${CATALINA_HOME}/webapps"
cp -a "${CATALINA_HOME}/webapps.dist/." "${CATALINA_HOME}/webapps/"
exec "${CATALINA_HOME}/bin/catalina.sh" run
ports: # 容器端口
- containerPort: 8080 # Tomcat HTTP 端口
---
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: tomcat-test05 # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 后端 Pod 选择器
app: tomcat-test05 # 选中 app=tomcat-test05 的 Pod
ports: # 端口映射
- port: 8080 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
# HTTPSwebsecure
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源HTTPS
metadata: # Ingress 元信息
name: tomcat-test05-acme # HTTPS Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: websecure # 使用 HTTPS 入口
traefik.ingress.kubernetes.io/router.tls.certresolver: cloudflare # 使用 Cloudflare certresolver
spec: # Ingress 规则
ingressClassName: traefik # 指定 IngressClass
tls: # TLS 配置
- hosts: # 证书覆盖域名
- test05.jackadam.top # 域名
rules: # 路由规则
- host: test05.jackadam.top # 主机匹配
http: # HTTP 路由定义
paths: # 路径列表
- path: / # 根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: tomcat-test05 # Service 名称
port: # Service 端口
number: 8080 # 端口号
---
# HTTPweb与 03-02 nginx-matrix-tls 一致:拆成两个 Ingress
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源HTTP
metadata: # Ingress 元信息
name: tomcat-test05-http # HTTP Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 HTTP 入口
spec: # Ingress 规则
ingressClassName: traefik # 指定 IngressClass
rules: # 路由规则
- host: test05.jackadam.top # 主机匹配
http: # HTTP 路由定义
paths: # 路径列表
- path: / # 根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: tomcat-test05 # Service 名称
port: # Service 端口
number: 8080 # 端口号