K8S 部署 ingress-nginx (二) 部署後端為 tomcat

klvchen發表於2018-11-07

在上面已經部署了 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/

相關文章