Skip to content
Permalink
Browse files

k8s部署

  • Loading branch information...
hb-chen committed Oct 13, 2019
1 parent d3f79f6 commit 8979073c7f473635e84d0300b61a749b66bc3bd1
@@ -0,0 +1,11 @@
# K8S部署

## plugin.go增加`kubernetes`注册中心插件
```go
package main
import (
// k8s registry
_ "github.com/micro/go-plugins/registry/kubernetes"
)
```
@@ -0,0 +1,19 @@
---
apiVersion: v1
kind: Service
metadata:
name: micro-api
namespace: default
labels:
name: micro-api
spec:
ports:
# the port that this service should serve on
- name: http
port: 80
targetPort: 8080
nodePort: 30001
# label keys and values that must match in order to receive traffic for this service
selector:
name: micro-api
type: LoadBalancer
@@ -0,0 +1,32 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
namespace: default
name: micro-api
spec:
replicas: 1
template:
metadata:
labels:
name: micro-api
spec:
serviceAccountName: micro-services
containers:
- name: api
command: [
"/micro",
"--registry=kubernetes",
"--server=rpc",
"--broker=http",
"--transport=tcp",
"--register_ttl=60",
"--register_interval=30",
"--selector=cache",
"--enable_stats",
"api"
]
image: hbchen/micro:k8s
imagePullPolicy: Always
ports:
- containerPort: 8080
name: api-port
@@ -0,0 +1,31 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: micro-services
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: micro-registry
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- list
- patch
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: micro-registry
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: micro-registry
subjects:
- kind: ServiceAccount
name: micro-services
namespace: default
@@ -0,0 +1,32 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
namespace: default
name: example-api
spec:
replicas: 1
template:
metadata:
labels:
name: example-api
spec:
serviceAccountName: micro-services
containers:
- name: example-api
resources:
requests:
cpu: "20m"
command: [
"/example-api",
"--registry=kubernetes",
"--server=rpc",
"--transport=tcp",
"--selector=cache",
"--server_address=0.0.0.0:9090",
"--broker_address=0.0.0.0:10001"
]
image: hbchen/micro-example-api:v0.0.1
imagePullPolicy: Always
ports:
- containerPort: 9090
name: api-port
@@ -0,0 +1,33 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
namespace: default
name: example-srv
spec:
replicas: 1
template:
metadata:
labels:
name: example-srv
micro: go.micro.srv.example
spec:
serviceAccountName: micro-services
containers:
- name: example-srv
resources:
requests:
cpu: "35m"
command: [
"/example-srv",
"--registry=kubernetes",
"--server=rpc",
"--transport=tcp",
"--selector=cache",
"--server_address=0.0.0.0:9090",
"--broker_address=0.0.0.0:10001"
]
image: hbchen/micro-example-srv:v0.0.1
imagePullPolicy: Always
ports:
- containerPort: 9090
name: srv-port
@@ -0,0 +1,55 @@
#!/bin/bash

# Just a script to run the demo
cmd=$1
dir=$2
kube=kubectl
list=( config/micro config/services )

start() {
if [ -z $dir ]; then
for dir in ${list[@]}; do
find $dir -name "*.yaml" | while read file; do
$kube apply -f $file
done
done
return
fi

find $dir -name "*.yaml" | while read file; do
$kube apply -f $file
done

}

stop() {
if [ -z $dir ]; then
for dir in ${list[@]}; do
find $dir -name "*.yaml" | while read file; do
$kube delete -f $file
done
done
return
fi

find $dir -name "*.yaml" | while read file; do
$kube delete -f $file
done
}

case $cmd in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "$0 <start|stop|restart> [dir]"
exit
;;
esac

0 comments on commit 8979073

Please sign in to comment.
You can’t perform that action at this time.