Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
rushuinet committed Aug 24, 2020
1 parent 2ef6a67 commit 31e1871
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

*.sum
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
COPY ./dev /usr/local/bin/dev
WORKDIR /usr/local/bin/
EXPOSE 80
CMD [ "dev" ]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:build

build:
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o dev .
docker build -t gogateway/dev .
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# dev
一个简单的k8s-ingress
# dev-ingress
一个简单的k8s-ingress,开发代理神器
# 背景
K8S集群内部的服务在外部不能访问,如需外部访问需要ingress做代理。官方有nginx-ingress,安装配置比较麻烦,想弄个简单的,只需要提交个表单就能配置完成的那种。

想到之前写的一个开发联调神器dev-proxy可以做简单的代理使用,配置方便。把她部署在k8s集群里是否就能直接配置服务了。。想到就做。。。。

k8s的nodePort端口(默认为30000-32767)我使用下面的方式修改的端口,可能有不同改法,自行百度
```
vim /etc/kubernetes/manifests/kube-apiserver.yaml
--service-node-port-range=80-65535
```
# 部署到k8s集群
```
kubectl apply -f k8s.yaml
kubectl apply -f dev-service.yaml
```
# 服务配置

- 访问集群中任意节点 http://ip/admin即可打开配置页面
- 如下图,有 kong-kong-proxy 服务在运行
```
# 查看集群中的服务
kubectl get svc -o wide
```
![image](doc/svc.jpg)
- 配置填写:kong=>kong-kong-proxy(后缀=>k8s的服务名,即可访问)
- 访问 http://ip/kong 即可看到效果
21 changes: 21 additions & 0 deletions deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: dev
labels:
app: dev
spec:
replicas: 1
selector:
matchLabels:
app: dev
template:
metadata:
labels:
app: dev
spec:
containers:
- name: dev
image: gogateway/dev:latest
ports:
- containerPort: 80
Binary file added doc/svc.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/gogateway/dev

go 1.14

require github.com/go-proxy/dev v0.1.1
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"flag"
"github.com/go-proxy/dev"
"log"
"net/http"
"os"
)

func main() {
port := os.Getenv("port")
if port == "" {
p := flag.String("port", "80", "port default 80")
port = *p
}
dev := dev.NewProxy()
log.Println("start port :" + port)
err := http.ListenAndServe(":"+port, dev)
if err != nil {
log.Fatal(err)
}
}
12 changes: 12 additions & 0 deletions service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: dev-service
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 80
selector:
app: dev

0 comments on commit 31e1871

Please sign in to comment.