Minikube Version : 1.36.0
K8S Version : 1.33.1
Docker Version : 28.1.1
OS: WSL ubuntu 24.04
Minikube is running on Docker
Hey, new to k8s here and want to put my sample app docker images into k8s. but run into problem in the process.
my sample docker image(simple-store-server) created using docker compose and contains:
- Postgres DB
- Golang Code
version: '3.0'
services:
postgres:
image: postgres:12-alpine
environment:
- POSTGRES_USER=alpine12
- POSTGRES_PASSWORD=password12
- POSTGRES_DB=simple_store
ports:
- "5000:5432"
volumes:
- postgres_db:/var/lib/postgresql/data
networks:
- mynetwork
server:
build:
context: .
dockerfile: Dockerfile
ports:
- "2000:2000"
environment:
- DB_CONNECTION=postgresql://alpine12:password12@postgres:5432/simple_store?sslmode=disable
depends_on:
- postgres
networks:
- mynetwork
entrypoint: ["/app/wait-for.sh","postgres:5432","--","/app/start.sh"]
command: ["/app/main"]
volumes:
postgres_db:
driver: local
networks:
mynetwork:
external: true
next is all the steps i done in order to put my docker image inside k8s:
1.using Kompose to create a bunch of yaml file
kompose convert -f compose.yaml
INFO Network mynetwork is detected at Source, shall be converted to equivalent NetworkPolicy at Destination
INFO Network mynetwork is detected at Source, shall be converted to equivalent NetworkPolicy at Destination
INFO Kubernetes file "postgres-service.yaml" created
INFO Kubernetes file "server-service.yaml" created
INFO Kubernetes file "postgres-deployment.yaml" created
INFO Kubernetes file "postgres-db-persistentvolumeclaim.yaml" created
INFO Kubernetes file "mynetwork-networkpolicy.yaml" created
INFO Kubernetes file "server-deployment.yaml" created
2.Modify server-deployment file to add ImagePullPolicy and changing image because its referencing to the wrong image in docker
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f compose.yaml
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
labels:
io.kompose.service: server
name: server
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: server
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert -f compose.yaml
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
labels:
io.kompose.network/mynetwork: "true"
io.kompose.service: server
spec:
containers:
- args:
- /app/main
command: ["/app/wait-for.sh", "postgres:5432", "--", "/app/start.sh"]
env:
- name: DB_CONNECTION
value: postgresql://alpine12:password12@postgres:5432/simple_store?sslmode=disable
image: simple-store-server ## original value=server
imagePullPolicy: Never
name: server
ports:
- containerPort: 2000
resources: {}
restartPolicy: Always
status: {}
3.run kubectl apply on all file
kubectl apply -f postgres-service.yaml,server-service.yaml,postgres-deployment.yaml,postgres-db-persistentvolumeclaim.yaml,mynetwork-networkpolicy.yaml,server-deployment.yaml
service/postgres configured
service/server configured
deployment.apps/postgres configured
persistentvolumeclaim/postgres-db configured
networkpolicy.networking.k8s.io/mynetwork configured
deployment.apps/server configured
kubectl get pods
NAME READY STATUS RESTARTS AGE
postgres-6b8b56c557-sn6vl 1/1 Running 0 8s
server-6b754c9f5c-2tjf7 1/1 Running 0 8s
kubectl get pods
NAME READY STATUS RESTARTS AGE
postgres-6b8b56c557-sn6vl 1/1 Running 0 31s
server-6b754c9f5c-2tjf7 1/1 Running 1 (15s ago) 31s
kubectl get pods
NAME READY STATUS RESTARTS AGE
postgres-6b8b56c557-sn6vl 1/1 Running 0 118s
server-6b754c9f5c-2tjf7 0/1 CrashLoopBackOff 3 (16s ago) 118s
here is my server pod logs:
kubectl logs server-6b754c9f5c-2tjf7
Operation timed out
Question:
1.why is “server” keep failing?
2.is it because the docker image?(miss matched name in steps 2 and i have to change it)
3.is “Operation Timed out” means my app cannot connect to db?(even though it works fine outside of k8s)