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

Fixes for StatefulSet deployment. Add questions.yml and app-readme.md for rancher chart #744

Merged
merged 41 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
08d37f0
add rancher chart options
jamesongithub Nov 17, 2021
e9493a5
lines
jamesongithub Nov 17, 2021
afd98c0
bump version
jamesongithub Nov 17, 2021
cfcb3e9
newline
jamesongithub Nov 17, 2021
facf188
options
jamesongithub Nov 17, 2021
01f096b
html break
jamesongithub Nov 17, 2021
1b796ee
newline
jamesongithub Nov 17, 2021
5c29c79
ss
jamesongithub Nov 17, 2021
7f0166c
add option for sa pasword
jamesongithub Dec 8, 2021
e0fe61a
secret
jamesongithub Dec 8, 2021
d67748c
Y
jamesongithub Dec 8, 2021
c4177d6
password
jamesongithub Dec 8, 2021
a013dcc
values files
jamesongithub Dec 8, 2021
4ef825d
Y
jamesongithub Dec 8, 2021
a94c976
sa password
jamesongithub Dec 8, 2021
6d830fa
labels
jamesongithub Dec 8, 2021
ce3d2c8
chart values
jamesongithub Dec 8, 2021
b97ed3b
fix envs
jamesongithub Dec 8, 2021
96edcde
icon
jamesongithub Jan 22, 2022
9c9f07a
add svg
jamesongithub Jan 22, 2022
571fb5d
move svg
jamesongithub Jan 22, 2022
9fe79f2
add icon to chart
jamesongithub Jan 22, 2022
26a68e3
product key as a show_if
jamesongithub Mar 11, 2022
45634da
tpl in values
jamesongithub Mar 11, 2022
d1733df
product key null
jamesongithub Mar 11, 2022
3c54fdc
show if
jamesongithub Mar 11, 2022
358f020
set description
jamesongithub Mar 11, 2022
3cc4246
use link to svg instead
jamesongithub Mar 12, 2022
8dd6229
rename deployment to statefulset
jamesongithub Mar 12, 2022
139e9e0
remove unneeded defaults in questions.yml
jamesongithub Mar 23, 2022
1325130
different labels
jamesongithub Mar 23, 2022
bbca54b
password requiremnts
jamesongithub Mar 23, 2022
72b5f37
questions
jamesongithub Mar 23, 2022
1699551
default
jamesongithub Mar 23, 2022
8f9f40a
remove html
jamesongithub Mar 23, 2022
251d244
remove defaults
jamesongithub Mar 23, 2022
2c0cc8b
Merge branch 'master' into jy/rancher
jamesongithub Apr 15, 2022
5654577
move changes to rancher dir
jamesongithub Apr 16, 2022
c7259e9
hide from rancher catalog
jamesongithub Apr 16, 2022
65c38b8
rename template functions
jamesongithub Apr 16, 2022
136a48f
formatting
jamesongithub Apr 16, 2022
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
25 changes: 25 additions & 0 deletions linux/rancher/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v2
name: sql-server-rancher
description: A Helm chart for SQL Server on Rancher

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 2019.cu15

icon: https://docs.microsoft.com/vi-vn/troubleshoot/media/hub-landing/sql-database-blue.svg
7 changes: 7 additions & 0 deletions linux/rancher/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: lint dry-run

lint:
helm lint --values ./values.test.yaml

template:
helm template --values ./values.test.yaml . --debug
1 change: 0 additions & 1 deletion linux/rancher/Readme

This file was deleted.

5 changes: 5 additions & 0 deletions linux/rancher/app-readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SQL Server

[Microsoft SQL Server](https://en.wikipedia.org/wiki/Microsoft_SQL_Server/) is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications—which may run either on the same computer or on another computer across a network (including the Internet). Microsoft markets at least a dozen different editions of Microsoft SQL Server, aimed at different audiences and for workloads ranging from small single-machine applications to large Internet-facing applications with many concurrent users.

This helm chart creates a SQL Server workload using StatefulSet along with a Service and Azure Disk storage class.
103 changes: 103 additions & 0 deletions linux/rancher/questions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
questions:
- variable: ACCEPT_EULA
label: ACCEPT_EULA
# no current support for html
# description: Accepts the SQL Server <a href="http://go.microsoft.com/fwlink/?LinkId=746388">EULA</a> (any value confirms acceptance).
description: Accepts the SQL Server EULA (any value confirms acceptance). The EULA is posted @ http://go.microsoft.com/fwlink/?LinkId=746388
required: true
group: SQL Server options

- variable: USE_PRODUCT_KEY
label: Use a SQL Server Product Key
description: Enter a Product Key instead of choosing a SQL Server Edition
type: boolean
default: false
group: SQL Server options

- variable: MSSQL_PID
label: SQL Server Edition aka. MSSQL_PID
description: Select a SQL Server Edition
type: enum
options:
- Evaluation
- Developer
- Express
- Web
- Standard
- Enterprise
required: true
show_if: USE_PRODUCT_KEY=false
group: SQL Server options

- variable: MSSQL_PID
label: SQL Server License Key
description: Enter a Product Key of the format "#####-#####-#####-#####-#####"
required: true
show_if: USE_PRODUCT_KEY=true
group: SQL Server options

- variable: MSSQL_SA_PASSWORD
label: MSSQL SA user password
description: Sets the SA user password. Password requirements @ https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15#password-complexity
type: password
min: 8
max: 128
default: ""
valid_chars: a-zA-Z0-9(`~!@#$%^&*_-+=|\\{}[]:;\"'<>,.?)/
required: true
group: SQL Server options

- variable: MSSQL_AGENT_ENABLED
label: Enable SQL Server Agent
description: Enables the SQL Server Agent
type: boolean
group: SQL Server options

- variable: defaultContainerImage
label: Use default SQL Server container image
type: boolean
default: true
show_subquestion_if: false
group: Container Image Options
subquestions:
- variable: image.repository
default: mcr.microsoft.com/mssql/server
description: Image Repository
label: Image Repository
- variable: image.pullPolicy
default: IfNotPresent
label: Image Pull Policy
type: enum
options:
- IfNotPresent
- Always
- Never
- variable: image.tag
default: 2019-latest
label: Image Tag

- variable: replicas
description: Replicas of the SQL Server StatefulSet
label: Replicas
type: int
group: Kubernetes StatefulSet options

- variable: podSecurityContext.fsGroup
description: |
Specifies a supplementary group id for all processes of the container.
See https://kubernetes.io/docs/tasks/configure-pod-container/security-context for
additional details.
label: podSecurityContext.fsGroup
group: Kubernetes Pod options

- variable: containers.ports.containerPort
description: >
Specifies containerPort for SQL Server
label: SQL Server Container Port
group: Kubernetes Pod Options

- variable: service.port
description: Kubernetes service port for SQL Server
group: Kubernetes Service Options
label: Kubernetes Service Port
type: int
137 changes: 137 additions & 0 deletions linux/rancher/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Readme.md

This HELM chart is a sample "as-is" chart provided for reference to help guide with SQL Server deployment on Kubernetes cluster.

## Prerequisites:

1. This chart is built on helm v3. It requires a kubernetes cluster to be running for you to deploy SQL container using this chart.
2. Ensure you have the helm installed on the client from where you will connect to the kubernetes cluster to deploy using the helm chart.
3. For minimum hardware requirement for the host to run SQL Server containers please refer to the system requirements section for SQL on Linux.
4. Requires the following variables to be set or changed in the values.yaml file :<br/>
a. Please ensure that you accept the EULA for SQL Server, by changing the value of ACCEPT_EULA.value=y in values.yaml file or set it during the helm install command --set ACCEPT_EULA.value=Y.<br/>
b. Please do choose the right edition of SQL Server that you would like to install you can change the value of the MSSQL_PID.value in the values file to the edition that you want to install or you can also
change it during the helm install command using the option --set MSSQL_PID.value=Enterprise, If you do not pass the flag and do not change it in the yaml, then by default it is going to install developer edition.<br/> c. Also please do provide your customized value for the sa_password, if you do not provide it then by default the sa_password will the value as shown in the below table.<br/>

Note: Once you deploy SQL server containers using the chart below, please log into SQL Server using sa account and change the password for sa, this ensures that as DBA you have the control of the sa user and password.


## Chart usage:

On the client machine where you have the Helm tools installed, download the chart on your machine and make the required changes to the values.yaml file as per your requirement. To see the list of settings that can be changed using the values.yaml file please refer to the table below.



| Configuration parameters | Description | Default_Value |
|----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------- |
| Values.image.repository | The SQL image to be downloaded and used for container deployment. | mcr.microsoft&#46;com/mssql/server |
| Values.image.tag | The tag of the image to be download for the specific SQL image. | 2019-latest |
| Values.ACCEPT_EULA.value | Set the ACCEPT_EULA variable to any value to confirm your acceptance of the SQL Server EULA, please refer environment variable for more details. | Y |
| 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.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.port | The service port number. | 1433 |
| Values.replicas | This value controls the number of SQL Server deployments that would be done, consider this as the number of SQL Server instances that will run. | 3 |

<br/>

## Deployment details:

> [!NOTE]
> Here are my deployment details, please make changes to the values.yaml or other files as per your requirement.

<br/>

In this scenario, I am deploying three SQL Server containers on a Azure Kubernetes Service (AKS) as statefulset deployments. You can follow [Setup and connect to AKS](https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal) to read instructions on setting up AKS and connecting to it. Also the storage class that I am using here is "Azure-disk". Please do find details below for each of the yaml file used in the template folder of this chart.

| File Name | Description |
|-|-|
| _helpers.tpl | Template file with all the template definitions that will be used in this chart. |
| deployment.yaml | A manifest file to describing the deployment details for SQL Server. |
| mssqlconfig.yaml | SQL server mssql.conf file and its content that you would like to mount to the SQL Server container. For parameters that you can pass in this file please refer mssql.conf documentation. To modify the mssql.conf settings please modify this file. |
| sc.yaml | A manifest file that describes the storage class (SC) to be deployed. To make any changes to the sc please modify this file accordingly. |
| service.yaml | A manifest file that defines the kubernetes service type and port. Because this is a statefulset deployment, this manifest files helps in creating the headless service. Please modify this for any service modification that is needed. |

<br/>

With this information, and probably after you have modified the required files you are now ready to deploy SQL Server using this chart. From the client machine where you have the helm chart installed, change the
directory of the CLI to the directory where you have the chart downloaded and to deploy SQL Server using this chart run the command:
<br/>


``` bash
helm install mssql . --set ACCEPT_EULA.value=Y --set MSSQL_PID.value=Developer
```
<br/>

After a few minutes this should deploy the SQL Server containers and you can see all the artifacts using the command :
<br/>

```bash
D:\helm-charts\sql-server-rancher>kubectl get all
```

The output should look as shown below:

<br/>

```bash
NAME READY STATUS RESTARTS AGE
pod/mssql-sql-server-rancher-0 1/1 Running 0 12m
pod/mssql-sql-server-rancher-1 1/1 Running 0 12m
pod/mssql-sql-server-rancher-2 1/1 Running 0 12m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/mssql-sql-server-rancher ClusterIP None <none> 1433/TCP 16m

NAME READY AGE
statefulset.apps/mssql-sql-server-rancher 3/3 16m
```

This chart also includes an extra folder called "services" this folder has two more manifest files as described below:

| Name | Description |
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ex_service.yaml | This containes sample code to create the external load balancer service for each of the pods created above, so SQL Server can be accessed outside the cluster |
| ag_endpoint.yaml | This containes sample code to expose the AG endpoint ports within the cluster, so each pod can talk to one another on the AG port. This will be needed if you are setting up AG between the pods. |

<br/>

Once you deploy the above files as well, using the commands shown below, you should have an external load balancer service created for each of the pods and another cluster IP service for each of the pod exposing the AG (alwayson) port for each pod within the cluster.


```bash
D:\helm-charts\sql-server-rancher>kubectl apply -f "D:\helm-charts\sql-server-rancher\services\ex_service.yaml"
D:\helm-charts\sql-server-rancher>kubectl apply -f "D:\helm-charts\sql-server-rancher\services\ag_endpoint.yaml"
```


Finally, after all the deployments here are the resources that you should see:


```bash
D:\>kubectl get all
NAME READY STATUS RESTARTS AGE
pod/mssql-sql-server-rancher-0 1/1 Running 0 127m
pod/mssql-sql-server-rancher-1 1/1 Running 0 126m
pod/mssql-sql-server-rancher-2 1/1 Running 0 125m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 220d
service/mssql-mirror-0 ClusterIP 10.0.148.0 <none> 5022/TCP 124m
service/mssql-mirror-1 ClusterIP 10.0.254.58 <none> 5022/TCP 124m
service/mssql-mirror-2 ClusterIP 10.0.196.129 <none> 5022/TCP 124m
service/mssql-sql-server-rancher ClusterIP None <none> 1433/TCP 127m
service/mssql-sql-server-rancher-0 LoadBalancer 10.0.238.203 104.211.231.206 1433:30923/TCP 124m
service/mssql-sql-server-rancher-1 LoadBalancer 10.0.96.108 104.211.203.78 1433:32695/TCP 124m
service/mssql-sql-server-rancher-2 LoadBalancer 10.0.78.10 104.211.203.159 1433:31042/TCP 124m

NAME READY AGE
statefulset.apps/mssql-sql-server-rancher 3/3 127m
```

## 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 pod service which in this case one such example is: to connect to mssql-sql-server-rancher-0 SQL Server, the IP address 104.211.231.206 will be used in ssms or any other client.

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).
62 changes: 62 additions & 0 deletions linux/rancher/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "sql-server-rancher.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
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 "sql-server-rancher.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "sql-server-rancher.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "sql-server-rancher.labels" -}}
helm.sh/chart: {{ include "sql-server-rancher.chart" . }}
{{ include "sql-server-rancher.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "sql-server-rancher.selectorLabels" -}}
app.kubernetes.io/name: {{ include "sql-server-rancher.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "sql-server-rancher.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "sql-server-rancher.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions linux/rancher/templates/mssqlconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: mssql
data:
mssql.conf: |
[EULA]
accepteula = Y
accepteulaml = Y

[coredump]
captureminiandfull = true
coredumptype = full

[hadr]
hadrenabled = 1

[language]
lcid = 1033
8 changes: 8 additions & 0 deletions linux/rancher/templates/sc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: azure-disk
provisioner: kubernetes.io/azure-disk
parameters:
storageaccounttype: Standard_LRS
kind: Managed
9 changes: 9 additions & 0 deletions linux/rancher/templates/secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: mssql-secret
labels:
{{- include "sql-server-rancher.labels" . | nindent 4 }}
type: Opaque
data:
mssql_sa_password : {{ .Values.MSSQL_SA_PASSWORD | b64enc | quote }}
Loading