~/snippets/k8s-azurite-create-container
Published on

Deploy Azurite Blob and create a container

479 words3 min read
# azurite-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azurite
spec:
  selector:
    matchLabels:
      app: azurite
  template:
    metadata:
      labels:
        name: azurite
        app: azurite
    spec:
      containers:
        - image: mcr.microsoft.com/azure-storage/azurite
          name: azurite
          command:
            - 'azurite-blob'
          args:
            - '--blobHost'
            - '0.0.0.0'
          ports:
            - name: http
              containerPort: 10000
      restartPolicy: Always
# azurite-service.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: azurite
spec:
  ports:
    - name: 'http'
      port: 10000
      targetPort: 10000
      nodePort: 30700
  selector:
    name: azurite
  type: NodePort
# create-storage-container.yaml
---
apiVersion: batch/v1
kind: Job
metadata:
  name: create-storage-container
spec:
  template:
    spec:
      initContainers:
        - name: 'init'
          image: busybox:1.36
          imagePullPolicy: 'IfNotPresent'
          command:
            [
              'sh',
              '-c',
              'echo -e "Checking azurite is available"; while ! nc -z azurite 10000; do sleep 1; printf "-"; done; echo -e "  >> azurite is ready";',
            ]
      containers:
        - name: 'main'
          image: mcr.microsoft.com/azure-cli:latest
          env:
            - name: AZURE_STORAGE_CONNECTION_STRING
              value: 'DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://azurite:10000/devstoreaccount1'
          command:
            - /bin/sh
          args:
            - -c
            - az storage container create --debug --name test-container
      restartPolicy: Never