Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Running Microsoft SQL Server pod on OpenShift

<p>&nbsp;</p> <quillbot-extension-portal></quillbot-extension-portal>

January 25, 2018
Takayoshi Tanaka
Related topics:
ContainersKubernetes
Related products:
Microsoft SQL Server on Red Hat Enterprise LinuxRed Hat OpenShift Container Platform

    Red Hat now supports Microsoft SQL Server running on RHEL Server. However, Red Hat doesn't provide an official docker image for MS SQL Server on RHEL. This post explains how to create a docker image for MS SQL Server on RHEL and run it on Red Hat OpenShift.

    Create a docker image for SQL Server on RHEL

    Microsoft provides an official docker image for SQL Server on Linux, however it's an Ubuntu based image.
    OpenShift doesn't restrict running Ubuntu based container image, but for those who prefer RHEL based image for reasons such as support, there is a Dockerfile in Microsoft Repository. Currently there are some importing pull requests that have no been merged yet.  To make things easier, I've provided a Dockerfile with those changes in my personal GitHub repository. You can build a docker image as follows:

    $ git clone https://github.com/tanaka-takayoshi/mssql-docker-rhel.git
    $ cd mssql-docker-rhel/cu
    $ docker build .

    To run this docker image on OpenShift, you have to push this image to OpenShift internal image registry by following this document.

    Create an OpenShift secret to store the password

    To avoid hard coding the password for the database's SA (sysadmin) user in a configuration file, you can specify that the  password is stored in an environment variable. You can set environment variables in deploymentconfig. However, any user who can read the deploymentconfig can see the password. to provide secure credential storage, OpenShift secrets are available. To create a secret, define a yaml file:

    apiVersion: v1
    kind: Secret
    metadata:
      name: mssql-env
    stringData:
      MSSQL_SA_PASSWORD: SpecialStr0ngP@ssW0rd

    Then create a secret.

    $ oc create -f mssql-env-secret.yaml

    It'll be used when deploying a image.

    Run an SQL Server image on OpenShift

    Now you can run the image on OpenShift. I chosen to use the OpenShift 3.7 Web Console.  Alternatively you can use the oc command line tool,  Click Add to Project | Deploy Image menu on the Web Console. Then select Image Stream Tag and input the image stream tag name when you pushed an image.

    deploy an image 1

    In the Environment Variable section, click Add Value from Config Map or Secret and the name of the secret.

    deploy an image 2

    OpenShift will start a new pod after you click the Deploy button.

    Connect to SQL Server

    You can connect to SQL Server pod with the service IP from within the OpenShift cluster network. By default, for security reasons, SQL Server doesn't remote connections. Follow this document and install SQL Server command-line tools. Then get a Service IP and connect to the database.

    get svc ip
    connect to sql

    Use a persistent volume to store data

    By default, anything written inside of a container will be lost when the pod has died. You can use a Persistent Volume to store data permanently. Since I'm running OpenShift 3.7 on Azure, I decided to use Azure Disk for my Persistent Volume. OpenShift 3.7 supports dynamic provisioning with Azure Managed Disk. Create a storage class by following this document.

    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
      name: managedhdd
    provisioner: kubernetes.io/azure-disk
    parameters:
      storageaccounttype: Standard_LRS
      kind: Managed
    $ create -f managedhdd.yaml
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
     name: pvc-mssql
     annotations:
       volume.beta.kubernetes.io/storage-provisioner: kubernetes.io/azure-disk
    spec:
     accessModes:
      - ReadWriteOnce
     resources:
       requests:
         storage: 10Gi
     storageClassName: slow
    $ oc create -f pvc-mssql.yaml

    If you configured it correctly, the persistent volume claim (PVC) will be in a bound state. It means OpenShift created  a new managed disk for this PVC.
    pvc

    Then, move on to the deployment in Web Console and click Actions | Add Storage menu.
    add storage

    Select created PVC and input /var/opt/mssql in the Mounted Path.
    add storage 2

    Now the data is stored on the Azure Disk and it won't be removed even though the pod has died. Let's delete a pod to confirm! The below screenshot shows the pod will restart on a new node when the existing pod mssql-2-k5r8q has been deleted.

    restart pod

    You can also confirm to connect by the same service IP address.
    query a database

    Last updated: November 17, 2023

    Recent Posts

    • Tekton joins the CNCF as an incubating project

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.