I am trying to configure my Kubernetes deployment for SQL Server database to be StatefulSet
to connect to my Web API.
This isw my .Yaml
file:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: firstone-mssql-statefulset
spec:
replicas: 1
serviceName: "firstone-mssql-service"
selector:
matchLabels:
app: firstone-mssql
template:
metadata:
labels:
app: firstone-mssql
spec:
containers:
- name: firstoneSQL
image: mcr.microsoft.com/mssql/server:2019-latest
resources:
limits:
memory: "2Gi"
cpu: "500m"
ports:
- containerPort: 1433
env:
- name: MSSQL_PID
value: "Developer"
- name: ACCEPT_EULA
value: "Y"
- name: SA_PASSWORD
valueFrom:
secretKeyRef:
name: firstone-mssql
key: SA_PASSWORD
volumeMounts:
- mountPath: /var/opt/mssql
name: data
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: firstone-mssql-service
spec:
selector:
app: firstone-mssql
type: LoadBalancer
ports:
- port: 1433
targetPort: 1433
When running the following command to get statefulsets
kubectl get statefulsets
I got the following
NAME READY AGE
firstone-mssql-statefulset 0/1 12m
Update
When running the following command to get pods
kubectl get pods
I got the following
NAME READY STATUS RESTARTS AGE
CodePudding user response:
Thanks to @MikołajGłodziak for his comment.
I did kubectl describe statefulset <your statefulset name>
and found the following issue
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedCreate 15h (x31 over 16h) statefulset-controller create Pod firstone-mssql-statefulset-0 in StatefulSet firstone-mssql-statefulset failed error: Pod "firstone-mssql-statefulset-0" is invalid: spec.containers[0].name: Invalid value: "firstoneSQL": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')
the issue is in the spec-> container-> name
spec:
containers:
- name: firstoneSQL <-- this is wrong label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character case
by changing this uppercase character to lower case character the statefulset created with ready status
spec:
containers:
- name: firstone-sql