About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

Multicontainer pod with volume of emptytype Vs one pod with multiple PVC attached.

 kushagrarakesh/multicontainers-empdir.yaml at main · kushagrarakesh/kushagrarakesh (github.com)

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: busybox
  name: multicontainer-empdir
spec:
  volumes:
  - name: var-logs
    emptyDir: {}
  containers:
  - image: busybox
    name: busybox1
    args:
    - bin/sh
    - -c
    - ls; sleep 3600
    volumeMounts:
    - name: var-logs
      mountPath: /usr/share/nginx/htm        
    resources: {}
  - image: alpine:latest
    name: alpine
    args:
    - bin/sh
    - -c
    - ls; sleep 3600
    volumeMounts:
    - name: var-logs
      mountPath: /usr/share/nginx/htm        
    resources: {}
  - image: nginx:latest
    name: nginx
    args:
    - bin/sh
    - -c
    - ls; sleep 3600
    volumeMounts:
    - name: var-logs
      mountPath: /usr/share/nginx/htm         
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}


use cases:- 


PS C:\Users\kusha\chap5> kubectl exec  -it  multicontainer-empdir -c nginx   -- sh 

W1028 11:23:05.759993    6300 azure.go:92] WARNING: the azure auth plugin is deprecated in v1.22+, unavailable in v1.26+; use https://github.com/Azure/kubelogin instead.

To learn more, consult https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins

# cd /usr/share/nginx/htm

# pwd

/usr/share/nginx/htm

#

This script is setting up a deployment for a SQL Server instance in a Kubernetes cluster with persistent storage using Azure Disk.

The script defines a StorageClass named azure-disk which will provision Azure disks for the Kubernetes cluster. Two PersistentVolumeClaims (PVCs) are defined, one for the mssql data folder and another for the mssql log folder. 

Each PVC specifies that it will use the azure-disk StorageClass and requests a specific amount of storage.

The Deployment definition includes two volume mounts, one for the mssql data folder and one for the mssql log folder. The mssqldb volume mount is mapped to the mssql-data PVC and the mssqllog volume mount is mapped to the mssql-log PVC. The SQL Server container in the deployment will have access to both of these volume mounts.

A Service is defined to expose the SQL Server deployment on port 1433 using a LoadBalancer type service. Finally, a Secret named mssql is defined that contains the SQL Server SA password encoded in base64.

---

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
     name: azure-disk
provisioner: kubernetes.io/azure-disk
parameters:
  storageaccounttype: Standard_LRS
  kind: Managed
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mssql-data
  annotations:
    volume.beta.kubernetes.io/storage-class: azure-disk
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mssql-log
  annotations:
    volume.beta.kubernetes.io/storage-class: azure-disk
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 4Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mssql-deployment
spec:
  replicas: 1
  selector:
     matchLabels:
       app: mssql
  template:
    metadata:
      labels:
        app: mssql
    spec:
      terminationGracePeriodSeconds: 30
      hostname: mssqlinst
      securityContext:
        fsGroup: 10001
      containers:
      - name: mssql
        image: mcr.microsoft.com/mssql/server:2019-latest
        resources:
          requests:
            memory: "2G"
            cpu: "2000m"
          limits:
            memory: "2G"
            cpu: "2000m"
        ports:
        - containerPort: 1433
        env:
        - name: MSSQL_PID
          value: "Developer"
        - name: ACCEPT_EULA
          value: "Y"
        - name: MSSQL_SA_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mssql
              key: MSSQL_SA_PASSWORD
        volumeMounts:
        - name: mssqldb
          mountPath: /var/opt/mssqldata
        - name: mssqllog
          mountPath: /var/opt/mssqllog          
      volumes:
      - name: mssqldb
        persistentVolumeClaim:
          claimName: mssql-data
      - name: mssqllog
        persistentVolumeClaim:
          claimName: mssql-log          

---
apiVersion: v1
kind: Service
metadata:
  name: mssql-deployment
spec:
  selector:
    app: mssql
  ports:
    - protocol: TCP
      port: 1433
      targetPort: 1433
  type: LoadBalancer
---
apiVersion: v1
data:
  MSSQL_SA_PASSWORD: TXlDMG05bCZ4UEBzc3cwcmQ=
kind: Secret
metadata:
  creationTimestamp: null
  name: mssql


Verify the services are running. Run the following command:

Use Case :- 

get the service Ip address 

kubectl get services 

C:\Users\kusha>kubectl get services

NAME                                             TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)                      AGE

mssql-deployment                                 LoadBalancer   10.0.130.195   20.85.151.114   1433:30264/TCP               66m


You can use the following applications to connect to the SQL Server instance.


  • SQL Server Managed Studio (SSMS)
  • SQL Server Data Tools (SSDT)
  • Azure Data Studio
  • Connect with sqlcmd

To connect with sqlcmd, run the following command:

Windows Command Prompt

sqlcmd -S  20.85.151.114  -U sa -P "MyC0m9l&xP@ssw0rd"

Replace the following values:

<External IP Address> with the IP address for the mssql-deployment service

MyC0m9l&xP@ssw0rd with your complex password

No comments: