Kubernetes — Пример манифеста пода с двумя контейнерами

Пример двух контейнеров в одном поде, где первый контейнер с приложением, а второй — Nginx, который проксирует на контейнер с приложением. Так же контейнеры используют общую директорию.

manifest.yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: example-config
  namespace: staging
  labels:
    app: example-app
data:
  POSTGRES_USER: "pg_user"
  POSTGRES_DB: "pg_db"
  POSTGRES_PASSWORD: "password"
  POSTGRES_HOST: "postgres-db-main"
  POSTGRES_PORT: "5432"

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-app
  namespace: staging
  labels:
    app: example-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example-app
  strategy:
    type: RollingUpdate
  progressDeadlineSeconds: 300
  template:
    metadata:
      labels:
        app: example-app
    spec:
      volumes:
      - name: shared-data
        emptyDir: {}
      containers:
      - image: XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/litslink:example-application
        name: example
        volumeMounts:
        - name: shared-data
          mountPath: /usr/src/app
        imagePullPolicy: "IfNotPresent"
        ports:
          - containerPort: 8080
        envFrom:
            - configMapRef:
                name: example-config
      - image: XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/base-image:example-nginx
        name: example-nginx
        volumeMounts:
        - name: shared-data
          mountPath: /usr/share/nginx/html
        imagePullPolicy: "IfNotPresent"
        ports:
          - containerPort: 80
      nodeSelector:
        nodegroup: staging

---

apiVersion: v1
kind: Service
metadata:
  name: example-svc
  namespace: staging
spec:
  ports:
  - port: 80
  selector:
    app: example-app

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ing
  namespace: staging
  annotations:
    kubernetes.io/ingress.class: ingress-staging
    certmanager.k8s.io/cluster-issuer: letsencrypt-prod
    certmanager.k8s.io/acme-challenge-type: dns01
    certmanager.k8s.io/acme-dns01-provider: dns
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  tls:
  - hosts:
    - example.artem.services
    secretName: example.artem.services-secret-tls
  rules:
  - host: example.artem.services
    http:
      paths:
      - path: /
        backend:
          serviceName: example-svc
          servicePort: 80

Nginx — app.conf

server {
    listen 80;
    listen [::]:80;
    location / {
            proxy_pass http://localhost:8080/;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Port $server_port;
    }
    location ^~ /storage/ {
        root /usr/src/app;
    }
}
0 0 vote
Рейтинг статьи

Метки: Метки

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