经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Nginx » 查看文章
K8S 部署 ingress-nginx (二) 部署后端为 tomcat
来源:cnblogs  作者:klvchen  时间:2018/11/8 9:34:22  对本文有异议

在上面已经部署了 ingress-nginx, https://www.cnblogs.com/klvchen/p/9903480.html

创建 service 和 pods

cd
vi tomcat-deploy.yaml 
# 内容为
apiVersion: v1
kind: Service
metadata:
  name: tomcat
  namespace: default
spec:
  selector:
    app: tomcat
    release: canary
  ports:
  - name: http
    targetPort: 8080
    port: 8080
  - name: ajp
    targetPort: 8009
    port: 8009

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deploy
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: tomcat
      release: canary
  template:
    metadata:
      labels:
        app: tomcat
        release: canary
    spec:
      containers:
      - name: tomcat
        image: tomcat:8.5.32-jre8-alpine
        ports:
        - name: http
          containerPort: 8080
          
kubectl apply -f tomcat-deploy.yaml

创建对应的 ingress

vi ingress-tomcat.yaml
# 内容为 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-tomcat
  namespace: default
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: tomcat.klvchen.com
    http:
      paths:
      - path:
        backend:
          serviceName: tomcat
          servicePort: 8080


kubectl apply -f ingress-tomcat.yaml 

# 通过修改 host 可以通过域名访问
http://tomcat.klvchen.com:30080/
 友情链接: NPS