暴露出一个微服务
echo "
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: httpbin
servicePort: 80
- path: /bar
backend:
serviceName: echo
servicePort: 80
" | kubectl apply -f -
ingress.extensions/demo created
在k8s中创建插件资源
echo '
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: add-response-header
config:
add:
headers:
- "demo: injected-by-kong"
plugin: response-transformer
' | kubectl apply -f -
kongplugin.configuration.konghq.com/add-response-header created
关联插件资源和入口资源----把插件应用到路由上
kubectl patch ingress demo -p '{"metadata":{"annotations":{"plugins.konghq.com":"add-response-header"}}}' ingress.extensions/demo patched
echo "
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo
annotations:
plugins.konghq.com: httpbin-auth
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: httpbin
servicePort: 80
" | kubectl apply -f -
$ echo "apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: httpbin-auth
plugin: key-auth
" | kubectl apply -f -
kongplugin.configuration.konghq.com/httpbin-auth created
关联插件到服务
kind: Service
apiVersion: v1
metadata:
labels:
app: fktaxctl-service
name: fktaxctl-service
namespace: chaolai
annotations:
plugins.konghq.com: add-response-header #应用插件到服务
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 29999
selector:
app: fktaxctl