新增learn-kubernetes(https://github.com/yyong-brs/learn-kubernetes)相关文件
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
apiVersion: networking.k8s.io/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: todo-api
|
||||
labels:
|
||||
kiamol: ch21
|
||||
spec:
|
||||
rules:
|
||||
- host: api.todo.kiamol.local
|
||||
http:
|
||||
paths:
|
||||
- path: /todos
|
||||
backend:
|
||||
serviceName: todo-api
|
||||
servicePort: 8080
|
||||
|
||||
# this spec is equivalent to running
|
||||
# kubeless trigger http create todo-api --function-name todo-api --path todos --hostname api.todo.kiamol.local
|
||||
# but that fails with Kubeless 1.0.7 running on Kubernetes 1.18 - see
|
||||
# https://github.com/kubeless/kubeless/issues/1130
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "todo-api",
|
||||
"version": "0.1.0",
|
||||
"main": "server.js",
|
||||
"author": "kiamol",
|
||||
"dependencies": {
|
||||
"nats" : "1.4.9",
|
||||
"uuid" : "8.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
const NATS = require('nats')
|
||||
const nc = NATS.connect({url: 'nats://message-queue:4222', json: true})
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
function handler(event, context) {
|
||||
console.log('** todo-api handler called');
|
||||
|
||||
var newItemEvent = {
|
||||
Subject: "events.todo.newitem",
|
||||
Item: {
|
||||
Item: event.data,
|
||||
DateAdded: new Date().toISOString()
|
||||
},
|
||||
CorrelationId: uuidv4()
|
||||
}
|
||||
|
||||
nc.publish('events.todo.newitem', newItemEvent)
|
||||
console.log(`** New item published, event ID: ${newItemEvent.CorrelationId}`);
|
||||
}
|
||||
|
||||
module.exports = { handler }
|
||||
Reference in New Issue
Block a user