I am new to Kubernetes in GCE-GKE, I was trying to build and deploy the nodeJS app in GCE-GKE cluster using the skaffold.Yaml. I can see image got build and also deployed withoutr any issue but when I tried to access GET the index.ts file on browser, I can't. I really don't understand what might have gone wrong or I may have missed something at LB or ingress-nginx.
Below id the skaffold.yaml
apiVersion: skaffold/v2alpha3
kind: Config
deploy:
kubectl:
manifests:
- ./infra/k8s/*
build:
# local:
# push: false
googleCloudBuild:
projectId: xxxxxxxxxxxx
artifacts:
- image: us.gcr.io/xxxxxxxxxxx/auth
context: auth
docker:
dockerfile: Dockerfile
sync:
manual:
- src: 'src/**/*.ts'
dest: .
Below is ingress-srv.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: ticketing.dev
http:
paths:
- path: /api/users/?(.*)
backend:
serviceName: auth-srv
servicePort: 3000
Below is 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: us.gcr.io/xxxxxxxxxxxxx/auth
---
apiVersion: v1
kind: Service
metadata:
name: auth-srv
spec:
selector:
app: auth
ports:
- name: auth
protocol: TCP
port: 3000
targetPort: 3000
Below is package.json
{
"name": "auth",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "ts-node-dev --poll src/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/express": "^4.17.6",
"express": "^4.17.1",
"nodemon": "^2.0.4",
"typescript": "^3.9.5"
},
"devDependencies": {
"ts-node-dev": "^1.0.0-pre.44"
}
}
Below is index.ts
import express from 'express';
import { json } from 'body-parser';
const app = express();
app.use(json());
// /api/users/currentuser
app.get('/users', (req, res) => {
res.send('Hello');
});
app.listen(3000, () => {
console.log('Great');
console.log('listening on port 3000!!!!!');
});
Below is docker file
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]
Which tools you use to manage domain configuraion?
Step 1: As far as i know, after you init nginx on your k8s cluster, you need add a DNS record to map a domain (or subdomain) in your domain (ticketing.dev) to external IP or external DNS of your k8s cluster which nginx have regenerated for you (i use an A record normally).
Step 2: After that, when you have deployed your application, you need to set the domain of your app (domain name you specify in your ingress yaml file) is a CNAME record of the above (A) record.
You can verify your domain verify cation by use nslookup
command. If you do not use proxy for your domain, both of above domain (A and CNAME record) will be resolve to the same your externall IP of your k8s cluster.
The purpose of 2 above steps is that you let the DNS server know where (which IP) to resolve when the DNS server get a req ask about any your subdomain (domain). That why you can use nslookup
command to verify your configuration.
Below is the tools i have used to manage DNS of our domain: https://www.namecheap.com/support/knowledgebase/article.aspx/9607/2210/how-to-set-up-dns-records-for-your-domain-in-cloudflare-account example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.