I want to locally setup a kubernetes deployment for a nextjs app for testing purposes.
I want to create a basic deployment for my app image with 3 replicas. So I have this yaml file.
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myappclient
image: myapp-image:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
type: LoadBalancer
ports:
- protocol: TCP
port: 3000
targetPort: 3000
So, this works fine but I need to have a shared volume for these replicas. After a lot of tries I had some errors especially with updating the ISR pages (e.g after updating content only one pod gets the changes etc). So now I have figure out that maybe I need to initialize an initContainer first to create the path where the data will be shared to pods. So I enchance the above (deployment part) file like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
initContainers:
- name: shared-volume
image: myapp-image:latest
command: ["sh", "-c", "mkdir -p /usr/src/mydata"]
volumeMounts:
- name: shared-data
mountPath: /usr/src/mydata
containers:
- name: myappclient
image: myapp-image:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
volumeMounts:
- name: shared-data
mountPath: /usr/src/mydata
restartPolicy: Always
volumes:
- name: shared-data
emptyDir: {}
where
/usr/src/mydata
is the path that I want & has created while building the image with Dockerfile.The case is that whatever I try I get the same errors:
kubectl logs <pod_name>:
Defaulted container "myappclient" out of: myappclient, shared-volume (init)
Error from server (BadRequest): container "myappclient" in pod "pod-name" is waiting to start: PodInitializing
kubectl describe pod <pod_name>:
Pulling image "myapp-image:latest"
Warning Failed 14m (x4 over 15m) kubelet Failed to pull image "myapp-image:latest": Error response from daemon: Get "http://localhost/v2/": dial tcp 127.0.0.1:80: connect: connection refused
Warning Failed 14m (x4 over 15m) kubelet Error: ErrImagePull
Warning Failed 14m (x6 over 15m) kubelet Error: ImagePullBackOff
(This running at windows machine using minikube for cluster setup and kubectl CLI)
Any ideas?
Thanks in advance!