I am trying to deploy a application with two pods (django and nginx)
how do i access the website on nginx container,
I am trying to access it on
- minikbe-ip:30007
- kubectl port-forward service/my-service 30007:80 => http://192.168.49.2:30007/
when i access it from 127.0.0.1:30007
I get error
403 Forbidden
nginx/1.19.0
this is default.conf file
upstream django-service {
server django-service:8000;
}
server {
listen 80;
location /api/ {
proxy_pass http://django-service;
}
location /static/rest_framework/ {
root /static/;
}
location / {
root /var/www/frontend;
try_files $uri $uri/ /index.html;
}
}
These are service information
C:\Users\Dell>kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 41d v1.28.3
C:\Users\Dell>minikube ip
192.168.49.2
C:\Users\Dell>kubectl get all
NAME READY STATUS RESTARTS AGE
pod/django-app-965fd6c5b-45clx 1/1 Running 1 4h54m
pod/nginx-app-557dcd558c-gbdjh 1/1 Running 0 20m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/django-service ClusterIP 10.110.164.131 <none> 8000/TCP 14h
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13d
service/my-service NodePort 10.111.8.176 <none> 80:30007/TCP 14h
service/nginx-service ClusterIP 10.103.234.114 <none> 80/TCP 14h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/django-app 1/1 1 1 4h54m
deployment.apps/nginx-app 1/1 1 1 20m
NAME DESIRED CURRENT READY AGE
replicaset.apps/django-app-965fd6c5b 1 1 1 4h54m
replicaset.apps/nginx-app-557dcd558c 1 1 1 20m
C:\Users\Dell>kubectl get pods
NAME READY STATUS RESTARTS AGE
django-app-965fd6c5b-45clx 1/1 Running 1 4h55m
nginx-app-557dcd558c-gbdjh 1/1 Running 0 20m
here are deployment files
and here are service informations
# Django Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: django-app
spec:
replicas: 1
selector:
matchLabels:
app: django-app
template:
metadata:
labels:
app: django-app
spec:
containers:
- name: django-container
image: ash414/e-cart-backend:v1.0
imagePullPolicy: Never
ports:
- containerPort: 8000
# Django Service
apiVersion: v1
kind: Service
metadata:
name: django-service
labels:
app: django-app
spec:
selector:
app: django-app
ports:
- protocol: TCP
port: 8000
targetPort: 8000
# Nginx Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-app
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx-app
template:
metadata:
labels:
app: nginx-app
spec:
containers:
- name: nginx-container
# image: e-cart-nginx:latest
# image: ash414/e-cart-nginx:v1.0v
image: ash414/e-cart-nginx-dj4:v1.0
ports:
- containerPort: 80
# Nginx Service
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: nginx
spec:
selector:
app: nginx-app
ports:
- protocol: TCP
port: 80
targetPort: 80
# NodePort Service
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: NodePort
selector:
app: nginx-app
ports:
- port: 80
targetPort: 80
nodePort: 30007