Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Kubernetes-Sample-Applocation

 ---

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-premium-retain-sc
provisioner: kubernetes.io/azure-disk
reclaimPolicy: Retain  # Default is Delete, recommended is retain
volumeBindingMode: WaitForFirstConsumer # Default is Immediate, recommended is WaitForFirstConsumer
allowVolumeExpansion: true  
parameters:
  storageaccounttype: Standard_LRS # or we can use Standard_LRS,Premium_LRS
  kind: managed # Default is shared (Other two are managed and dedicated)
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: azure-managed-disk-pvc
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: managed-premium-retain-sc
  resources:
    requests:
      storage: 5Gi
---
# postgres-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
data:
  init-db.sql: |
    CREATE DATABASE raj_bzr8;
    \c raj_bzr8;
    CREATE TABLE users (
      id SERIAL PRIMARY KEY,
      username VARCHAR(255) NOT NULL
    );
  POSTGRES_USER: raj
  POSTGRES_PASSWORD: v41ULZUpiewfWDO46kvLCfxmIypuOtox
---
# postgres-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres-container
        image: postgres:latest
        envFrom:
        - configMapRef:
            name: postgres-config
        ports:
        - containerPort: 5432
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/postgresql
        - name: init-script
          mountPath: /docker-entrypoint-initdb.d
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: azure-managed-disk-pvc
      - name: init-script
        configMap:
          name: postgres-config
          items:
          - key: init-db.sql
            path: init-db.sql
---
# postgres-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: postgres-service
spec:
  selector:
    app: postgres
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432
---
# flask-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: flask-config
data:
  DATABASE_URL: postgres://raj:v41ULZUpiewfWDO46kvLCfxmIypuOtox@postgres-service:5432/raj_bzr8
---
# flask-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: flask-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flask-app
  template:
    metadata:
      labels:
        app: flask-app
    spec:
      initContainers:
      - name: wait-for-postgres
        image: busybox
        command: ['sh', '-c', 'until nc -z -w 5 postgres-service 5432; do echo "Waiting for PostgreSQL to start"; sleep 5; done;']
      containers:
      - name: flask-container
        image: rajeshsingam/prod-working-flask:latest
        ports:
        - containerPort: 5000
        envFrom:
        - configMapRef:
            name: flask-config
        readinessProbe:
          httpGet:
            path: /
            port: 5000
          initialDelaySeconds: 5
          periodSeconds: 10
        # livenessProbe:
        #   httpGet:
        #     path: /health
        #     port: 5000
        #   initialDelaySeconds: 10
        #   periodSeconds: 30
---
# flask-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: flask-service
spec:
  selector:
    app: flask-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 5000
  type: LoadBalancer

Post a Comment

0 Comments

Ad Code

Responsive Advertisement