Kubernetes — Deployment, Service и Ingress

Пример манифестов для запуска двух контейнеров доступных с мира при помощи Ingress'a

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: app1
  template:
    metadata:
      labels:
        app: app1
    spec:
      containers:
      - name: app1
        image: dockersamples/static-site
        env:
        - name: AUTHOR
          value: app1
        ports:
        - containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app2
spec:
  replicas: 2
  selector:
    matchLabels:
      app: app2
  template:
    metadata:
      labels:
        app: app2
    spec:
      containers:
      - name: app2
        image: dockersamples/static-site
        env:
        - name: AUTHOR
          value: app2
        ports:
        - containerPort: 80

Service:

apiVersion: v1
kind: Service
metadata:
  name: app1
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: app1
---
apiVersion: v1
kind: Service
metadata:
  name: app2
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: app2

Ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: app
spec:
  rules:
  - host: test.site.com
    http:
      paths:
      - backend:
          serviceName: app1
          servicePort: 80
        path: /app1
      - backend:
          serviceName: app2
          servicePort: 80
        path: /app2

test.site.com — меняем на нужный домен, и после этого:

  • test.site.com/app1 — будет отвечать контейнер app1;
  • test.site.com/app2 — будет отвечать контейнер app2.
0 0 vote
Рейтинг статьи

Метки: Метки

Подписаться
Уведомление о
guest
0 комментариев
Inline Feedbacks
View all comments