Skip to content

Commit

Permalink
Topology Initial Commit
Browse files Browse the repository at this point in the history
- Refactor private networking -> topology
- Define new topology models (no changes yet)
- Docs
- Create cluster --topology and -t
- New functions for topology templating
  • Loading branch information
krisnova committed Oct 23, 2016
1 parent 18cc365 commit 7f4004b
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 80 deletions.
65 changes: 43 additions & 22 deletions cmd/kops/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,33 @@ import (
)

type CreateClusterOptions struct {
Yes bool
Target string
Models string
Cloud string
Zones string
MasterZones string
NodeSize string
MasterSize string
NodeCount int
Project string
KubernetesVersion string
OutDir string
Image string
SSHPublicKey string
VPCID string
NetworkCIDR string
DNSZone string
AdminAccess string
Networking string
AssociatePublicIP bool
Yes bool
Target string
Models string
Cloud string
Zones string
MasterZones string
NodeSize string
MasterSize string
NodeCount int
Project string
KubernetesVersion string
OutDir string
Image string
SSHPublicKey string
VPCID string
NetworkCIDR string
DNSZone string
AdminAccess string
Networking string
AssociatePublicIP bool

// Channel is the location of the api.Channel to use for our defaults
Channel string
Channel string

// The network topology to use
Topology string

}

func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
Expand Down Expand Up @@ -111,6 +115,9 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {

cmd.Flags().StringVar(&options.Channel, "channel", api.DefaultChannel, "Channel for default versions and configuration to use")

// Network topology
cmd.Flags().StringVarP(&options.Topology, "topology", "t", "public", "Controls network topology for the cluster. public|private|hybrid1. Default is 'public'.")

return cmd
}

Expand Down Expand Up @@ -359,6 +366,20 @@ func RunCreateCluster(f *util.Factory, cmd *cobra.Command, args []string, out io
}
}

// Network Topology

switch c.Topology{
case api.TopologyPublic:
cluster.Spec.Topology = &api.TopologySpec{Type: api.TopologyPublic}
case api.TopologyPrivate:
cluster.Spec.Topology = &api.TopologySpec{Type: api.TopologyPrivate}
case api.TopologyHybrid1:
cluster.Spec.Topology = &api.TopologySpec{Type: api.TopologyHybrid1}
default:
glog.Warningf("Unable to detect topology. Defaulting to public topology.")
cluster.Spec.Topology = &api.TopologySpec{Type: api.TopologyPublic}
}

sshPublicKeys := make(map[string][]byte)
if c.SSHPublicKey != "" {
c.SSHPublicKey = utils.ExpandPath(c.SSHPublicKey)
Expand Down Expand Up @@ -505,4 +526,4 @@ func parseZoneList(s string) []string {
filtered = append(filtered, v)
}
return filtered
}
}
41 changes: 41 additions & 0 deletions docs/topology.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Network Topologies in Kops

Kops supports a number of pre defined network topologies. They are separated into commonly used scenarios, or topologies.

Each of the supported topologies are listed below, with an example on how to deploy them.

## AWS

Kops supports the following topologies on AWS

| Topology | Value | Description |
| ----------------- |----------- | ----------------------------------------------------------------------------------------------------------- |
| Public Cluster | public | All masters/nodes will be launched in a **public subnet** in the VPC |
| Private Cluster | private | All masters/nodes will be launched in a **private subnet** in the VPC |
| Hybrid (1) | hybrid1 | All masters will be launched into a **private subnet**, All nodes will be launched into a **public subnet** |


#### Defining a topology on create

To specify a topology use the `--topology` or `-t` flag as in :

```
kops create cluster ... --topology public|private|hybrid1
```


#### Defining a topology in the cluster configuration

The topology definition in the kops configuration is as follows

```
topology:
type: public|private|hybrid1
```

Where kops will default to a public topology

```
topology:
type: public
```
19 changes: 17 additions & 2 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ type ClusterSpec struct {
// NetworkID is an identifier of a network, if we want to reuse/share an existing network (e.g. an AWS VPC)
NetworkID string `json:"networkID,omitempty"`

// Topology defines the type of network topology to use on the cluster - default public
Topology *TopologySpec `json:"topology,omitempty"`

// SecretStore is the VFS path to where secrets are stored
SecretStore string `json:"secretStore,omitempty"`
// KeyStore is the VFS path to where SSL keys and certificates are stored
Expand Down Expand Up @@ -343,8 +346,6 @@ func (c *Cluster) FillDefaults() error {
// OK
} else if c.Spec.Networking.External != nil {
// OK
} else if c.Spec.Networking.CNI != nil {
// OK
} else {
// No networking model selected; choose Kubenet
c.Spec.Networking.Kubenet = &KubenetNetworkingSpec{}
Expand Down Expand Up @@ -486,3 +487,17 @@ func (z *ClusterZoneSpec) assignCIDR(c *Cluster) (string, error) {
func (c *Cluster) SharedVPC() bool {
return c.Spec.NetworkID != ""
}

// --------------------------------------------------------------------------------------------
// Network Topology functions for template parsing
//
// Each of these functions can be used in the model templates
// The go template package currently only supports boolean
// operations, so the logic is mapped here as *Cluster functions.
//
// A function will need to be defined for all new topologies, if we plan to use them in the
// model templates.
// --------------------------------------------------------------------------------------------
func (c *Cluster) IsTopologyPrivate() bool { return c.Spec.Topology.Type == TopologyPrivate }
func (c *Cluster) IsTopologyPublic() bool { return c.Spec.Topology.Type == TopologyPublic }
func (c *Cluster) IsTopologyHybrid1() bool { return c.Spec.Topology.Type == TopologyHybrid1 }
27 changes: 27 additions & 0 deletions pkg/apis/kops/topology.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package kops

const (
TopologyPublic = "public"
TopologyPrivate = "private"
TopologyHybrid1 = "hybrid1"
)

type TopologySpec struct {
Type string `json:"type,omitempty"`
}
52 changes: 0 additions & 52 deletions upup/models/cloudup/_aws/network.yaml

This file was deleted.

53 changes: 53 additions & 0 deletions upup/models/cloudup/_aws/topologies/hybrid1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{ if IsTopologyHybrid1 }}
vpc/{{ ClusterName }}:
id: {{ .NetworkID }}
shared: {{ SharedVPC }}
cidr: {{ .NetworkCIDR }}
enableDnsSupport: true
enableDnsHostnames: true


{{ if not SharedVPC }}
# TODO: would be good to create these as shared, to verify them
dhcpOptions/{{ ClusterName }}:
domainNameServers: AmazonProvidedDNS
{{ if eq Region "us-east-1" }}
domainName: ec2.internal
{{ else }}
domainName: {{ Region }}.compute.internal
{{ end }}

vpcDHDCPOptionsAssociation/{{ ClusterName }}:
vpc: vpc/{{ ClusterName }}
dhcpOptions: dhcpOptions/{{ ClusterName }}
{{ end }}

internetGateway/{{ ClusterName }}:
shared: {{ SharedVPC }}
vpc: vpc/{{ ClusterName }}

routeTable/{{ ClusterName }}:
vpc: vpc/{{ ClusterName }}

route/0.0.0.0/0:
routeTable: routeTable/{{ ClusterName }}
cidr: 0.0.0.0/0
internetGateway: internetGateway/{{ ClusterName }}
vpc: vpc/{{ ClusterName }}

{{ range $zone := .Zones }}

subnet/{{ $zone.Name }}.{{ ClusterName }}:
vpc: vpc/{{ ClusterName }}
availabilityZone: {{ $zone.Name }}
cidr: {{ $zone.CIDR }}
id: {{ $zone.ProviderID }}
shared: {{ SharedZone $zone }}

{{ if not (SharedZone $zone) }}
routeTableAssociation/{{ $zone.Name }}.{{ ClusterName }}:
routeTable: routeTable/{{ ClusterName }}
subnet: subnet/{{ $zone.Name }}.{{ ClusterName }}
{{ end}}
{{ end }}
{{ end }}
53 changes: 53 additions & 0 deletions upup/models/cloudup/_aws/topologies/private.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{ if IsTopologyPrivate }}
vpc/{{ ClusterName }}:
id: {{ .NetworkID }}
shared: {{ SharedVPC }}
cidr: {{ .NetworkCIDR }}
enableDnsSupport: true
enableDnsHostnames: true


{{ if not SharedVPC }}
# TODO: would be good to create these as shared, to verify them
dhcpOptions/{{ ClusterName }}:
domainNameServers: AmazonProvidedDNS
{{ if eq Region "us-east-1" }}
domainName: ec2.internal
{{ else }}
domainName: {{ Region }}.compute.internal
{{ end }}

vpcDHDCPOptionsAssociation/{{ ClusterName }}:
vpc: vpc/{{ ClusterName }}
dhcpOptions: dhcpOptions/{{ ClusterName }}
{{ end }}

internetGateway/{{ ClusterName }}:
shared: {{ SharedVPC }}
vpc: vpc/{{ ClusterName }}

routeTable/{{ ClusterName }}:
vpc: vpc/{{ ClusterName }}

route/0.0.0.0/0:
routeTable: routeTable/{{ ClusterName }}
cidr: 0.0.0.0/0
internetGateway: internetGateway/{{ ClusterName }}
vpc: vpc/{{ ClusterName }}

{{ range $zone := .Zones }}

subnet/{{ $zone.Name }}.{{ ClusterName }}:
vpc: vpc/{{ ClusterName }}
availabilityZone: {{ $zone.Name }}
cidr: {{ $zone.CIDR }}
id: {{ $zone.ProviderID }}
shared: {{ SharedZone $zone }}

{{ if not (SharedZone $zone) }}
routeTableAssociation/{{ $zone.Name }}.{{ ClusterName }}:
routeTable: routeTable/{{ ClusterName }}
subnet: subnet/{{ $zone.Name }}.{{ ClusterName }}
{{ end}}
{{ end }}
{{ end }}
Loading

0 comments on commit 7f4004b

Please sign in to comment.