Reputation: 3368
I'm trying to figure out how the docker command docker run -p 8080:80 webapp
to kubernetes yaml. I have a nginx dockerized and the image works fine when I start it with the command mentioned above. When I push it to kubernetes, nothing happens.
Dockerfile:
FROM nginx:1.13.3-alpine
COPY nginx/default.conf /etc/nginx/conf.d/
RUN rm -rf /usr/share/nginx/html/*
COPY ./dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
My Kubernetes deployment
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: webapp-production
spec:
replicas: 1
template:
metadata:
name: webapp
labels:
app: webapp
role: frontend
env: production
spec:
containers:
- name: webapp
image: eu.gcr.io/projectxyz/webapp:1.0.0
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: ENVIRONMENT
value: "production"
resources:
limits:
memory: "500Mi"
cpu: "100m"
imagePullPolicy: Always
ports:
- name: webapp
containerPort: 8080
My Service
kind: Service
apiVersion: v1
metadata:
name: webapp
spec:
selector:
app: webapp
role: frontend
type: NodePort
ports:
- name: http
port: 8080
- name: external
port: 80
targetPort: 8080
Do I have to run a command in kubernetes? Are the ports configured correct? Thanks for the help.
/////// Edit /////
Message from pod logs: The selected container has not logged any messages yet.
Upvotes: 1
Views: 4520
Reputation: 22932
You are targeting the wrong port here. From what I see this app starts nginx on port 80, yet your service definition targets port 8080 on endpoint pods. As there is no traffic reaching nginx, nothing will get logged on stdout access log. Change your service definition to direct traffic on correct port (80) and that should do the trick.
Sidenote: if container would not start / terminate prematurely you would probably see a crashloop state on your pod.
Upvotes: 1