Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for node selector and tolerations #796

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
name: mssql-latest
name: mssql-server
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ On the client machine where you have the Helm tools installed, download the char
| Values.MSSQL_PID.value | Set the SQL Server edition or product key. please refer environment variable for more details | Developer |
| Values.MSSQL_AGENT_ENABLED.value | Enable SQL Server Agent. For example, 'true' is enabled and 'false' is disabled. By default, agent is disabled. please refer environment variable for more details. | TRUE |
| Values.hostname | The name that you would like to see when you run the select @@servername for the SQL instance running inside the container. | mssqllatest |
| Values.sa_password | Configure the SA user password. | StrongPass1! |
| Values.sa_password | Configure the SA user password. | Toughpass1! |
| Values.containers.ports.containerPort | Port on which the SQL Server is listening inside the container. | 1433 |
| Values.podSecurityContext.fsgroup | Security context at the pod level. | 10001 |
| Values.service.type | The type of the service to be created within the kubernetes cluster. | LoadBalancer |
Expand Down Expand Up @@ -65,35 +65,35 @@ directory of the CLI to the directory where you have the chart downloaded and to


``` bash
helm install mssql-latest-deploy . --set ACCEPT_EULA.value=Y --set MSSQL_PID.value=Developer
helm install mssql-server-deploy . --set ACCEPT_EULA.value=Y --set MSSQL_PID.value=Developer
```


After a few seconds this should deploy the SQL Server containers and you can see all the artifacts using the command :

```bash
D:\helm-charts\mssql-latest\mssql-latest>kubectl get all
D:\helm-charts\mssql-server\mssql-server>kubectl get all
```

The output should look as shown below:

```bash
NAME READY STATUS RESTARTS AGE
pod/mssql-latest-deploy-645c4dddd8-647zk 1/1 Running 4 23h
pod/mssql-server-deploy-645c4dddd8-647zk 1/1 Running 4 23h

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 140d
service/mssql-latest-deploy LoadBalancer 10.0.57.19 20.44.43.212 1433:30544/TCP 23h
service/mssql-server-deploy LoadBalancer 10.0.57.19 20.44.43.212 1433:30544/TCP 23h

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/mssql-latest-deploy 1/1 1 1 23h
deployment.apps/mssql-server-deploy 1/1 1 1 23h

NAME DESIRED CURRENT READY AGE
replicaset.apps/mssql-latest-deploy-645c4dddd8 1 1 1 23h
replicaset.apps/mssql-server-deploy-645c4dddd8 1 1 1 23h
```

## Connect to SQL Server

Now you are ready to connect to the SQL Server using any of the familiar tools that you work with, like the [SSMS](https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver15) (SQL Server Management Studio) or [SQLCMD](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) or [ADS](https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15) (Azure Data Studio), etc. The IP address that you will use to connect is the External-IP address for the mssql-latest-deploy service which in this case is 20.44.43.212 that will be used to connect to SQL Server.
Now you are ready to connect to the SQL Server using any of the familiar tools that you work with, like the [SSMS](https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver15) (SQL Server Management Studio) or [SQLCMD](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) or [ADS](https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15) (Azure Data Studio), etc. The IP address that you will use to connect is the External-IP address for the mssql-server-deploy service which in this case is 20.44.43.212 that will be used to connect to SQL Server.

For more details on the SQL Server deployment on AKS using manual method please refer [Deploy a SQL Server container in Kubernetes with Azure Kubernetes Services (AKS)](https://docs.microsoft.com/en-us/sql/linux/tutorial-sql-server-containers-kubernetes?view=sql-server-ver15).
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "mssql-latest.name" -}}
{{- define "mssql-server.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

Expand All @@ -10,7 +10,7 @@ Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "mssql-latest.fullname" -}}
{{- define "mssql-server.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand All @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "mssql-latest.chart" -}}
{{- define "mssql-server.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "mssql-latest.labels" -}}
helm.sh/chart: {{ include "mssql-latest.chart" . }}
{{ include "mssql-latest.selectorLabels" . }}
{{- define "mssql-server.labels" -}}
helm.sh/chart: {{ include "mssql-server.chart" . }}
{{ include "mssql-server.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand All @@ -45,26 +45,25 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Selector labels
*/}}
{{- define "mssql-latest.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mssql-latest.name" . }}
{{- define "mssql-server.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mssql-server.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "mssql-latest.serviceAccountName" -}}
{{- define "mssql-server.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "mssql-latest.fullname" .) .Values.serviceAccount.name }}
{{- default (include "mssql-server.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}


{{/*
Create the name for the SA password secret key.
*/}}
{{- define "mssql.sapassword" -}}
{{- define "mssql-server.sapassword" -}}
sa_password
{{- end -}}
81 changes: 81 additions & 0 deletions linux/sample-helm-chart-deployment/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mssql-server.name" . }}
labels:
{{- include "mssql-server.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicas}}
selector:
matchLabels:
{{- include "mssql-server.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "mssql-server.selectorLabels" . | nindent 8 }}
spec:
{{- if .Values.nodeSelector }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.tolerations }}
tolerations:
{{ toYaml .Values.tolerations | indent 6 }}
{{- end }}
hostname: {{ .Values.hostname}}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
command:
- /bin/bash
- -c
- cp /var/opt/config/mssql.conf /var/opt/mssql/mssql.conf && /opt/mssql/bin/sqlservr
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.containers.ports.containerPort}}
env:
- name: MSSQL_PID
value: "{{ .Values.MSSQL_PID.value}}"
- name: ACCEPT_EULA
value: "{{ .Values.ACCEPT_EULA.value | upper}}"
- name: MSSQL_AGENT_ENABLED
value: "{{ .Values.MSSQL_AGENT_ENABLED.value}}"
- name: SA_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mssql-server.name" . }}-secret
key: {{ template "mssql-server.sapassword" . }}
volumeMounts:
- name: {{ include "mssql-server.name" . }}-data-volume
mountPath: "/var/opt/mssql"
{{/* mountPath: {{ .Values.pvc.dataMountPath }}
- name: {{ include "mssql-server.name" . }}-log-volume
mountPath: {{ .Values.pvc.logMountPath }}
- name: {{ include "mssql-server.name" . }}-dump-volume
mountPath: {{ .Values.pvc.dumpMountPath }}
- name: {{ include "mssql-server.name" . }}-backup-volume
mountPath: {{ .Values.pvc.backupMountPath }} */}}
- name: {{ include "mssql-server.name" . }}-config-volume
mountPath: /var/opt/config
volumes:
- name: {{ include "mssql-server.name" . }}-data-volume
persistentVolumeClaim:
claimName: {{ include "mssql-server.name" . }}-data
{{/* - name: {{ include "mssql-server.name" . }}-log-volume
persistentVolumeClaim:
claimName: {{ include "mssql-server.name" . }}-log
- name: {{ include "mssql-server.name" . }}-dump-volume
persistentVolumeClaim:
claimName: {{ include "mssql-server.name" . }}-dump
- name: {{ include "mssql-server.name" . }}-backup-volume
persistentVolumeClaim:
claimName: {{ include "mssql-server.name" . }}-backup */}}
- name: {{ include "mssql-server.name" . }}-config-volume
configMap:
name: {{ include "mssql-server.name" . }}-config
26 changes: 26 additions & 0 deletions linux/sample-helm-chart-deployment/templates/mssqlconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ include "mssql-server.name" . }}-config
data:
mssql.conf: |
[EULA]
accepteula = Y
accepteulaml = Y

[coredump]
captureminiandfull = true
coredumptype = full

[hadr]
hadrenabled = 1

[language]
lcid = 1033
{{/*
[filelocation]
{{- printf "defaultdatadir = %s" .Values.pvc.dataMountPath | nindent 4 -}}
{{- printf "defaultlogdir = %s" .Values.pvc.logMountPath | nindent 4 -}}
{{- printf "defaultdumpdir = %s" .Values.pvc.dumpMountPath | nindent 4 -}}
{{- printf "defaultbackupdir = %s" .Values.pvc.backupMountPath | nindent 4 -}}
*/}}
56 changes: 56 additions & 0 deletions linux/sample-helm-chart-deployment/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "mssql-server.name" . }}-data
# annotations:
# volume.beta.kubernetes.io/storage-class: {{ .Values.pvc.storageClass | quote }}
spec:
storageClassName: {{ .Values.pvc.storageClass | quote }}
accessModes:
- {{ .Values.pvc.dataAccessMode | quote}}
resources:
requests:
storage: {{ .Values.pvc.dataSize}}
{{/*---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "mssql-server.name" . }}-log
# annotations:
# volume.beta.kubernetes.io/storage-class: {{ .Values.pvc.storageClass}}
spec:
storageClassName: {{ .Values.pvc.storageClass | quote }}
accessModes:
- {{ .Values.pvc.logAccessMode | quote}}
resources:
requests:
storage: {{ .Values.pvc.logSize}}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "mssql-server.name" . }}-dump
# annotations:
# volume.beta.kubernetes.io/storage-class: {{ .Values.pvc.storageClass}}
spec:
storageClassName: {{ .Values.pvc.storageClass | quote }}
accessModes:
- {{ .Values.pvc.dumpAccessMode | quote}}
resources:
requests:
storage: {{ .Values.pvc.dumpSize}}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "mssql-server.name" . }}-backup
# annotations:
# volume.beta.kubernetes.io/storage-class: {{ .Values.pvc.storageClass}}
spec:
storageClassName: {{ .Values.pvc.storageClass | quote }}
accessModes:
- {{ .Values.pvc.backupAccessMode | quote}}
resources:
requests:
storage: {{ .Values.pvc.backupSize}}
*/}}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: mssql-secret
labels:
{{- include "mssql-latest.labels" . | nindent 4 }}
type: Opaque
data:
apiVersion: v1
kind: Secret
metadata:
name: {{ include "mssql-server.name" . }}-secret
labels:
{{- include "mssql-server.labels" . | nindent 4 }}
type: Opaque
data:
sa_password : {{ .Values.sa_password | b64enc | quote}}
18 changes: 18 additions & 0 deletions linux/sample-helm-chart-deployment/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "mssql-server.name" . }}
labels:
{{- include "mssql-server.labels" . | nindent 4 }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.port }}
protocol: TCP
selector:
{{- include "mssql-server.selectorLabels" . | nindent 4 }}
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# Default values for mssql-latest.
# Default values for mssql-server.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicas: 1

nameOverride: ''
fullnameOverride: ''

image:
repository: mcr.microsoft.com/mssql/server
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "2019-latest"

nodeSelector: {}

tolerations: []

ACCEPT_EULA:
value: "y"
MSSQL_PID:
Expand All @@ -30,16 +37,19 @@ podSecurityContext:
service:
type: LoadBalancer
port: 1433
annotations: {}

pvc:
StorageClass: "azure-disk"
userdbaccessMode: ReadWriteOnce
userdbsize: 5Gi
userlogaccessMode: ReadWriteOnce
userlogsize: 5Gi
tempdbaccessMode: ReadWriteOnce
tempsize: 2Gi
mssqldataaccessMode: ReadWriteOnce
mssqldbsize: 2Gi


storageClass: ""
dataAccessMode: ReadWriteOnce
dataSize: 5Gi
# dataMountPath: /var/opt/mssql/db/data
# logAccessMode: ReadWriteOnce
# logSize: 5Gi
# logMountPath: /var/opt/mssql/db/log
# dumpAccessMode: ReadWriteOnce
# dumpSize: 2Gi
# dumpMountPath: /var/opt/mssql/db/dump
# backupAccessMode: ReadWriteOnce
# backupSize: 2Gi
# backupMountPath: /var/opt/mssql/db/backup
Loading