0

I'm new at k8s and I'm trying to set up ingress nginx for kubernates deployments and services so that I can access the server from browser. Im using kubuntu os. Here are the steps I'm following to achive this .

Files

auth-depl.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: suhravshan/auth

---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000

ingress-srv.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"

spec:
  rules:
    - host: tickets.com
      http:
        paths:
          - path: /api/users/?(.*)
            pathType: Prefix
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000

skaffold.yaml

apiVersion: skaffold/v3alpha1
kind: Config
metadata:
  name: ticketing
build:
  local:
    push: false
  artifacts:
    - image: suhravshan/auth
      context: auth
      docker:
        dockerfile: Dockerfile
manifests:
  rawYaml:
    - infra/k8s/*

First starting minikube in ubuntu os by

minikube start

Then giving skaffold dev command and getting this output

Build [suhravshan/auth] succeeded
Tags used in deployment:
 - suhravshan/auth -> suhravshan/auth:f502d429fdd0f7a5981125b8d9d2913c3c830e4f713af6a51a605e330ac79c1c
Starting deploy...
 - deployment.apps/auth-depl created
 - service/auth-srv created
 - ingress.networking.k8s.io/ingress-service created
Waiting for deployments to stabilize...
 - deployment/auth-depl: creating container auth
    - pod/auth-depl-575db79fc8-px9fh: creating container auth
 - deployment/auth-depl is ready.
Deployments stabilized in 6.547 seconds
Listing files to watch...
 - suhravshan/auth
Press Ctrl+C to exit
Watching for changes...
[auth] 
[auth] > auth@1.0.0 start
[auth] > ts-node-dev src/index.ts
[auth] 
[auth] [INFO] 15:12:01 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.9.1, typescript ver. 5.0.4)
[auth] Listening on port 3000 !!```

More Info

❯ kubectl get deployments

NAME        READY   UP-TO-DATE   AVAILABLE   AGE
auth-depl   1/1     1            1           105s
❯ kubectl get svc        

NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
auth-srv     ClusterIP   10.106.225.251   <none>        3000/TCP   2m35s
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP    16m
❯ kubectl get pods -n kube-system

NAME                               READY   STATUS    RESTARTS      AGE
coredns-787d4945fb-k297q           1/1     Running   0             26m
etcd-minikube                      1/1     Running   0             27m
kube-apiserver-minikube            1/1     Running   0             27m
kube-controller-manager-minikube   1/1     Running   1 (27m ago)   27m
kube-proxy-vzw5v                   1/1     Running   0             26m
kube-scheduler-minikube            1/1     Running   0             27m
storage-provisioner                1/1     Running   1 (26m ago)   26m`
❯ nslookup tickets.com

Server:         127.0.0.53
Address:        127.0.0.53#53

Name:   tickets.com
Address: 10.0.2.15
❯ minikube ip                                       
10.0.2.15
❯ kubectl get pods -n ingress-nginx
NAME                                        READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-bpzsr        0/1     Completed   0          9m24s
ingress-nginx-admission-patch-bc7mp         0/1     Completed   1          9m24s
ingress-nginx-controller-6cc5ccb977-5qckr   1/1     Running     0          9m24s

I have also added minikube addons enable ingress and also added the line is hosts file 10.0.2.15 tickets.com

So whenever Im trying to access the server from browser through http://tickets.com/api/users/currentuser its saying site is not reachable. How can I solve the issue?

0 Answers0