Skip to content

Instantly share code, notes, and snippets.

@dbafromthecold
Last active December 14, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbafromthecold/a126b33c2b8fe0c02b9081e8d447c21a to your computer and use it in GitHub Desktop.
Save dbafromthecold/a126b33c2b8fe0c02b9081e8d447c21a to your computer and use it in GitHub Desktop.
Setting up a helm chart to deploy SQL Server to a K8s cluster
# create directory for helm
cd C:\git\dbafromthecold\PrivateCodeRepo\Azure\Helm
# create new chart
helm create testsqlchart
# navigate to templates
cd testsqlchart/templates
# remove deployment.yaml
rm deployment.yaml
# re-create deployments.yaml
echo 'apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: sqlserver
labels:
app: sqlserver
spec:
replicas: 1
template:
metadata:
labels:
name: sqlserver
spec:
containers:
- name: sqlserver1
image: mcr.microsoft.com/mssql/server:2019-CTP2.2-ubuntu
ports:
- containerPort: 1433
env:
- name: SA_PASSWORD
value: "Testing1122"
- name: ACCEPT_EULA
value: "Y"' > deployment.yaml
# delete service.yaml file
rm service.yaml
# re-create service.yaml file
echo 'apiVersion: v1
kind: Service
metadata:
name: sqlserver-service
spec:
ports:
- name: sqlserver
port: 1433
targetPort: 1433
selector:
name: sqlserver
type: LoadBalancer' > service.yaml
# initialise helm
# this will point at the K8s cluster in ~/.kube/config
helm init
# tiller pod should be up and running
kubectl get pods --namespace kube-system
# navigate back
cd C:\git\dbafromthecold\PrivateCodeRepo\Azure\Helm
# test a deployment with --dry-run
helm install --dry-run --debug ./testsqlchart
################################################################################################################################
################################################################################################################################
# if error run this...
# delete current tiller deployment
kubectl delete deployment tiller-deploy --namespace kube-system
# create a service account
kubectl create serviceaccount --namespace kube-system tiller
# create clusterrolebinding
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
# re-initialise tiller
helm init --service-account tiller --upgrade
# update repos
helm update repo .
# re-try the dry run
helm install --dry-run --debug ./testsqlchart
################################################################################################################################
################################################################################################################################
# try the deployment
helm install ./testsqlchart --name testsqlserver
# confirm deployment
kubectl get deployment
# confirm pods
kubectl get pods
# confirm service
kubectl get service
# connect to sql
mssql-cli -S IPADDRESS -U sa -P Testing1122
# confirm version of SQL
SELECT @@VERSION;
# exit SQL
exit
# list releases
helm list
# test delete
helm delete --dry-run testsqlserver
# delete release
helm delete testsqlserver
# confirm delete
helm list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment