Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
456b395860 | ||
|
|
f3c367a323 | ||
|
|
a32028c4fb |
4
core/discov/kubernetes/discov-namespace.yaml
Normal file
4
core/discov/kubernetes/discov-namespace.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: discov
|
||||||
368
core/discov/kubernetes/etcd.yaml
Normal file
368
core/discov/kubernetes/etcd.yaml
Normal file
@@ -0,0 +1,368 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: etcd
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: etcd-port
|
||||||
|
port: 2379
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2379
|
||||||
|
selector:
|
||||||
|
app: etcd
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: etcd
|
||||||
|
etcd_node: etcd0
|
||||||
|
name: etcd0
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- /usr/local/bin/etcd
|
||||||
|
- --name
|
||||||
|
- etcd0
|
||||||
|
- --initial-advertise-peer-urls
|
||||||
|
- http://etcd0:2380
|
||||||
|
- --listen-peer-urls
|
||||||
|
- http://0.0.0.0:2380
|
||||||
|
- --listen-client-urls
|
||||||
|
- http://0.0.0.0:2379
|
||||||
|
- --advertise-client-urls
|
||||||
|
- http://etcd0:2379
|
||||||
|
- --initial-cluster
|
||||||
|
- etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380,etcd4=http://etcd4:2380
|
||||||
|
- --initial-cluster-state
|
||||||
|
- new
|
||||||
|
image: quay.io/coreos/etcd:latest
|
||||||
|
name: etcd0
|
||||||
|
ports:
|
||||||
|
- containerPort: 2379
|
||||||
|
name: client
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 2380
|
||||||
|
name: server
|
||||||
|
protocol: TCP
|
||||||
|
affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- etcd
|
||||||
|
topologyKey: "kubernetes.io/hostname"
|
||||||
|
restartPolicy: Always
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
etcd_node: etcd0
|
||||||
|
name: etcd0
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: client
|
||||||
|
port: 2379
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2379
|
||||||
|
- name: server
|
||||||
|
port: 2380
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2380
|
||||||
|
selector:
|
||||||
|
etcd_node: etcd0
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: etcd
|
||||||
|
etcd_node: etcd1
|
||||||
|
name: etcd1
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- /usr/local/bin/etcd
|
||||||
|
- --name
|
||||||
|
- etcd1
|
||||||
|
- --initial-advertise-peer-urls
|
||||||
|
- http://etcd1:2380
|
||||||
|
- --listen-peer-urls
|
||||||
|
- http://0.0.0.0:2380
|
||||||
|
- --listen-client-urls
|
||||||
|
- http://0.0.0.0:2379
|
||||||
|
- --advertise-client-urls
|
||||||
|
- http://etcd1:2379
|
||||||
|
- --initial-cluster
|
||||||
|
- etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380,etcd4=http://etcd4:2380
|
||||||
|
- --initial-cluster-state
|
||||||
|
- new
|
||||||
|
image: quay.io/coreos/etcd:latest
|
||||||
|
name: etcd1
|
||||||
|
ports:
|
||||||
|
- containerPort: 2379
|
||||||
|
name: client
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 2380
|
||||||
|
name: server
|
||||||
|
protocol: TCP
|
||||||
|
affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- etcd
|
||||||
|
topologyKey: "kubernetes.io/hostname"
|
||||||
|
restartPolicy: Always
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
etcd_node: etcd1
|
||||||
|
name: etcd1
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: client
|
||||||
|
port: 2379
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2379
|
||||||
|
- name: server
|
||||||
|
port: 2380
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2380
|
||||||
|
selector:
|
||||||
|
etcd_node: etcd1
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: etcd
|
||||||
|
etcd_node: etcd2
|
||||||
|
name: etcd2
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- /usr/local/bin/etcd
|
||||||
|
- --name
|
||||||
|
- etcd2
|
||||||
|
- --initial-advertise-peer-urls
|
||||||
|
- http://etcd2:2380
|
||||||
|
- --listen-peer-urls
|
||||||
|
- http://0.0.0.0:2380
|
||||||
|
- --listen-client-urls
|
||||||
|
- http://0.0.0.0:2379
|
||||||
|
- --advertise-client-urls
|
||||||
|
- http://etcd2:2379
|
||||||
|
- --initial-cluster
|
||||||
|
- etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380,etcd4=http://etcd4:2380
|
||||||
|
- --initial-cluster-state
|
||||||
|
- new
|
||||||
|
image: quay.io/coreos/etcd:latest
|
||||||
|
name: etcd2
|
||||||
|
ports:
|
||||||
|
- containerPort: 2379
|
||||||
|
name: client
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 2380
|
||||||
|
name: server
|
||||||
|
protocol: TCP
|
||||||
|
affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- etcd
|
||||||
|
topologyKey: "kubernetes.io/hostname"
|
||||||
|
restartPolicy: Always
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
etcd_node: etcd2
|
||||||
|
name: etcd2
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: client
|
||||||
|
port: 2379
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2379
|
||||||
|
- name: server
|
||||||
|
port: 2380
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2380
|
||||||
|
selector:
|
||||||
|
etcd_node: etcd2
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: etcd
|
||||||
|
etcd_node: etcd3
|
||||||
|
name: etcd3
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- /usr/local/bin/etcd
|
||||||
|
- --name
|
||||||
|
- etcd3
|
||||||
|
- --initial-advertise-peer-urls
|
||||||
|
- http://etcd3:2380
|
||||||
|
- --listen-peer-urls
|
||||||
|
- http://0.0.0.0:2380
|
||||||
|
- --listen-client-urls
|
||||||
|
- http://0.0.0.0:2379
|
||||||
|
- --advertise-client-urls
|
||||||
|
- http://etcd3:2379
|
||||||
|
- --initial-cluster
|
||||||
|
- etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380,etcd4=http://etcd4:2380
|
||||||
|
- --initial-cluster-state
|
||||||
|
- new
|
||||||
|
image: quay.io/coreos/etcd:latest
|
||||||
|
name: etcd3
|
||||||
|
ports:
|
||||||
|
- containerPort: 2379
|
||||||
|
name: client
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 2380
|
||||||
|
name: server
|
||||||
|
protocol: TCP
|
||||||
|
affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- etcd
|
||||||
|
topologyKey: "kubernetes.io/hostname"
|
||||||
|
restartPolicy: Always
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
etcd_node: etcd3
|
||||||
|
name: etcd3
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: client
|
||||||
|
port: 2379
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2379
|
||||||
|
- name: server
|
||||||
|
port: 2380
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2380
|
||||||
|
selector:
|
||||||
|
etcd_node: etcd3
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: etcd
|
||||||
|
etcd_node: etcd4
|
||||||
|
name: etcd4
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- command:
|
||||||
|
- /usr/local/bin/etcd
|
||||||
|
- --name
|
||||||
|
- etcd4
|
||||||
|
- --initial-advertise-peer-urls
|
||||||
|
- http://etcd4:2380
|
||||||
|
- --listen-peer-urls
|
||||||
|
- http://0.0.0.0:2380
|
||||||
|
- --listen-client-urls
|
||||||
|
- http://0.0.0.0:2379
|
||||||
|
- --advertise-client-urls
|
||||||
|
- http://etcd4:2379
|
||||||
|
- --initial-cluster
|
||||||
|
- etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380,etcd4=http://etcd4:2380
|
||||||
|
- --initial-cluster-state
|
||||||
|
- new
|
||||||
|
image: quay.io/coreos/etcd:latest
|
||||||
|
name: etcd4
|
||||||
|
ports:
|
||||||
|
- containerPort: 2379
|
||||||
|
name: client
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 2380
|
||||||
|
name: server
|
||||||
|
protocol: TCP
|
||||||
|
affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- etcd
|
||||||
|
topologyKey: "kubernetes.io/hostname"
|
||||||
|
restartPolicy: Always
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
etcd_node: etcd4
|
||||||
|
name: etcd4
|
||||||
|
namespace: discov
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: client
|
||||||
|
port: 2379
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2379
|
||||||
|
- name: server
|
||||||
|
port: 2380
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 2380
|
||||||
|
selector:
|
||||||
|
etcd_node: etcd4
|
||||||
@@ -213,6 +213,7 @@ func Infof(format string, v ...interface{}) {
|
|||||||
func Must(err error) {
|
func Must(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := formatWithCaller(err.Error(), 3)
|
msg := formatWithCaller(err.Error(), 3)
|
||||||
|
log.Print(msg)
|
||||||
output(severeLog, levelFatal, msg)
|
output(severeLog, levelFatal, msg)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func (d *directBuilder) Build(target resolver.Target, cc resolver.ClientConn, op
|
|||||||
resolver.Resolver, error) {
|
resolver.Resolver, error) {
|
||||||
var addrs []resolver.Address
|
var addrs []resolver.Address
|
||||||
endpoints := strings.FieldsFunc(target.Endpoint, func(r rune) bool {
|
endpoints := strings.FieldsFunc(target.Endpoint, func(r rune) bool {
|
||||||
return r == EndpointSep
|
return r == EndpointSepChar
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, val := range subset(endpoints, subsetSize) {
|
for _, val := range subset(endpoints, subsetSize) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type discovBuilder struct{}
|
|||||||
func (d *discovBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (
|
func (d *discovBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (
|
||||||
resolver.Resolver, error) {
|
resolver.Resolver, error) {
|
||||||
hosts := strings.FieldsFunc(target.Authority, func(r rune) bool {
|
hosts := strings.FieldsFunc(target.Authority, func(r rune) bool {
|
||||||
return r == EndpointSep
|
return r == EndpointSepChar
|
||||||
})
|
})
|
||||||
sub, err := discov.NewSubscriber(hosts, target.Endpoint)
|
sub, err := discov.NewSubscriber(hosts, target.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
package resolver
|
package resolver
|
||||||
|
|
||||||
import "google.golang.org/grpc/resolver"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/resolver"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DirectScheme = "direct"
|
DirectScheme = "direct"
|
||||||
DiscovScheme = "discov"
|
DiscovScheme = "discov"
|
||||||
EndpointSep = ','
|
EndpointSepChar = ','
|
||||||
subsetSize = 32
|
subsetSize = 32
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dirBuilder directBuilder
|
EndpointSep = fmt.Sprintf("%c", EndpointSepChar)
|
||||||
disBuilder discovBuilder
|
dirBuilder directBuilder
|
||||||
|
disBuilder discovBuilder
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterResolver() {
|
func RegisterResolver() {
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BuildDirectTarget(endpoints []string) string {
|
func BuildDirectTarget(endpoints []string) string {
|
||||||
return fmt.Sprintf("%s:///%s", resolver.DirectScheme, strings.Join(
|
return fmt.Sprintf("%s:///%s", resolver.DirectScheme,
|
||||||
endpoints, fmt.Sprintf("%c", resolver.EndpointSep)))
|
strings.Join(endpoints, resolver.EndpointSep))
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildDiscovTarget(endpoints []string, key string) string {
|
func BuildDiscovTarget(endpoints []string, key string) string {
|
||||||
return fmt.Sprintf("%s://%s/%s", resolver.DiscovScheme, strings.Join(
|
return fmt.Sprintf("%s://%s/%s", resolver.DiscovScheme,
|
||||||
endpoints, fmt.Sprintf("%c", resolver.EndpointSep)), key)
|
strings.Join(endpoints, resolver.EndpointSep), key)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user