Configure SQL Server's Listening Port
This guide explains how to set the TCP port that SQL Server listens on inside the DxSqlAg SQL Server container, and how the operator decides which value to use.
The goal is that you always know which port SQL Server is using, and that you can see it directly on the DxSqlAg custom resource.
Prerequisites
- DxOperator installed in the Kubernetes cluster.
Default SQL Server Behavior
If you don’t configure anything, SQL Server listens on the default port:
- Default TCP port:
1433
The operator treats 1433 as "no custom port was requested" unless you explicitly set a different value.
For security best practices, do not use the default SQL Server port (1433) when configuring SQL Server instances in production environments. Using the default port can expose your instance to automated scanning and brute-force attacks. In production environments, it is strongly recommended to configure a non-standard port to reduce the attack surface and improve security posture.
Where the Port can be Configured
There are three places you can (indirectly or directly) set the SQL Server TCP port:
- A field on the
DxSqlAgspec:spec.statefulSetSpec.podSpec.mssqlServerContainer.mssqlTcpPort
- An environment variable on the SQL Server container:
MSSQL_TCP_PORT
- The SQL Server configuration file (
mssql.conf) stored in a ConfigMap:network.tcpportinmssql.conf
When the operator processes a new DxSqlAg, it picks a port using this precedence order:
mssqlTcpPortfield in the CR (if not1433)MSSQL_TCP_PORTenvironment variable (if present and valid)network.tcpportinmssql.conffrom the ConfigMap referenced bymssqlConfigMap- Fallback:
1433(default)
Whichever value wins is then written back into the DxSqlAg CR:
spec.statefulSetSpec.podSpec.mssqlServerContainer.mssqlTcpPort
So the CR’s mssqlTcpPort field always reflects the effective port.
The SQL Server TCP port can only be set during the DxSqlAg creation - you must delete the DxSqlAg to change the port!
Option 1: Set the Port in the DxSqlAg Spec (Recommended)
The simplest and most "operator-native" way is to set the port directly on the DxSqlAg spec. The operator will:
- Use that value as the source of truth.
- Ensure the container is configured to use that port (including setting the
MSSQL_TCP_PORTenv var for you when needed).
Example: Set SQL Server to Listen on Port 11433
apiVersion: dh2i.com/v1
kind: DxSqlAg
metadata:
name: dxsqlag
spec:
statefulSetSpec:
podSpec:
mssqlServerContainer:
mssqlTcpPort: 11433
# Optional: if you have other env vars, keep them here
# env:
# - name: SOME_OTHER_FOO
# value: "bar"
- You don’t need to manually set
MSSQL_TCP_PORTif you configuremssqlTcpPort. The operator will create or update that env var when appropriate. - Avoid setting a conflicting port in
mssql.confat the same time. Pick one place to define the port and keep it consistent.
Option 2: Use the MSSQL_TCP_PORT Environment Variable
You can also set the port via the SQL Server container environment, as long as:
mssqlTcpPortis left at its default (1433), and- you configure
MSSQL_TCP_PORTto the desired port.
The operator will:
- Read
MSSQL_TCP_PORT, - Use that as the effective port, and
- Update
mssqlTcpPorton the CR to match.
Example: Set Port using MSSQL_TCP_PORT
apiVersion: dh2i.com/v1
kind: DxSqlAg
metadata:
name: example-sqlag
spec:
statefulSetSpec:
podSpec:
mssqlServerContainer:
mssqlTcpPort: 1433 # Leave at default or omit entirely so env var takes precedence
env:
- name: MSSQL_TCP_PORT
value: "11433"
Option 3: Use mssql.conf via a ConfigMap
If you already manage SQL Server settings via mssql.conf, you can specify the TCP port there and point the container at that ConfigMap.
In that case, the operator will:
- Look up the ConfigMap referenced in
mssqlConfigMap, - Read the
mssql.confentry, - Parse the
network.tcpportvalue, - Use that as the effective port, and
- Update
mssqlTcpPortin the CR accordingly.
Example: Set Port using mssql.conf
-
Create a ConfigMap.
- YAML
- CLI
configmap.yamlkind: ConfigMap
apiVersion: v1
metadata:
name: my-mssql-config
data:
mssql.conf: |
[network]
tcpport = 11433kubectl create configmap my-mssql-config \
--from-literal=mssql.conf="[network]
tcpport=11433
" -
Reference the ConfigMap in the
DxSqlAgapiVersion: dh2i.com/v1
kind: DxSqlAg
metadata:
name: dxsqlag
spec:
statefulSetSpec:
podSpec:
mssqlServerContainer:
mssqlTcpPort: 1433 # Leave at default or omit entirely
mssqlConfigMap: my-mssql-config
- If
network.tcpportis missing or empty in mssql.conf, SQL Server is treated as using the default port (1433). - In this "ConfigMap-driven" mode, the operator reads the value but does not force a
MSSQL_TCP_PORTenv var for it. The important part is that the CR'smssqlTcpPortfield is updated to match what’s inmssql.conf.
Keeping Things Consistent
To avoid confusion, pick one primary configuration method (spec field, env var, or ConfigMap) and keep the others either unset or aligned.
The operator always tries to keep the CR’s mssqlTcpPort field in sync with the actual port, based on the rules described above.
Verifying the Configured Port
After you change the port, check the CR:
kubectl get dxsqlag dxsqlag -o yaml | grep mssqlTcpPort
Confirm that mssqlTcpPort shows the value you expect.
Optionally, you can also check inside SQL Server. Connect to the instance and run:
SELECT local_tcp_port
FROM sys.dm_exec_connections
WHERE session_id = @@SPID;
This will show the actual port that your session is using.
Configure External Load Balancers
This step is only required if per-pod external access is needed. If per-pod external access is required, custom LoadBalancer services can be created using service templates.