Reputation: 540
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
namespace: cp1
spec:
selector:
matchLabels:
app: mysql
serviceName: mysql
replicas: 1
template:
metadata:
labels:
app: mysql
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mysql
image: mysql:latest
env:
- name: MYSQL_ROOT_HOST
value: '%'
- name: MYSQL_LOG_CONSOLE
value: "true"
- name: MYSQL_ROOT_PASSWORD
valueFrom:
configMapKeyRef:
key: MYSQL_PASSWORD
name: env-map-service
ports:
- containerPort: 3306
name: mysql
resources:
requests:
cpu: 500m
memory: 1Gi
volumeMounts:
- name: mysql-vol
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: mysql-vol
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
storageClassName: test-sc
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: cp1
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
ports:
- port: 3306
name: mysql
targetPort: 3306
clusterIP: None
selector:
app: mysql
Its my app deployment yaml file. which work perfectly,
apiVersion: apps/v1
kind: Deployment
metadata:
name: kube-child-app
labels:
app: kube-child-app
namespace: cp1
spec:
replicas: 1
template:
metadata:
name: kube-child-app
labels:
app: kube-child-app
spec:
containers:
- name: kube-child-app
image: jahadulrakib/kube-child-app:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8081
restartPolicy: Always
selector:
matchLabels:
app: kube-child-app
I want to deploy a database application in my local kubernetes cluster. But its gives following error and do not run pod. here i attach my yaml file for pod up. i create for this StroageClass, PV.
Error: Error from server (BadRequest): pod mysql-0 does not have a host assigned
UPDATE 1:
Warning FailedScheduling 5h40m default-scheduler 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims
pvc and pv are in pending status
UPDATE 2:
PVC in pending
status because storage class cant create the needed PV
15m Warning FailedScheduling pod/mysql-0 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims. 4m12s Normal ExternalProvisioning persistentvolumeclaim/mysql-vol-mysql-0 waiting for a volume to be created, either by external provisioner "docker.io/hostpath" or manually created by system administrator
UPDATE 3:
the issue seems to stem from difference between the available PV labels and configuration we want to use and the ones set in the statefulSet volumeClaimTemplates
Upvotes: 2
Views: 1238
Reputation: 5404
Looks like the PVC was not satisfied with the needed PV because the storageClass didnt create a new PV and the existing PV didnt match the Pending
PVC so they couldnt bound together. after changing the appropriate fields they bound together.
Although it only uses a single replica a statefulSet is still the best option over using a deployment with a pvc instead mainly because of the application intention being a DB scaling a birds eye view of the project explain the application meaning better when using a statefulSet since it is stateful and it can in the future turn into a set of pods instead of just one.
check out kubernetes article on it when is was first popularised and set as in useful state, and theire current docs on it
Upvotes: 2