Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
7c9b6e90
Commit
7c9b6e90
authored
May 19, 2017
by
Bowei Du
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a subnet for reserving the service cluster IP range
This will be done if IP aliases is enabled on GCP.
parent
8d0cce3f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
12 deletions
+51
-12
config-default.sh
cluster/gce/config-default.sh
+2
-0
config-test.sh
cluster/gce/config-test.sh
+2
-0
util.sh
cluster/gce/util.sh
+47
-12
No files found.
cluster/gce/config-default.sh
View file @
7c9b6e90
...
@@ -198,6 +198,8 @@ if [ ${ENABLE_IP_ALIASES} = true ]; then
...
@@ -198,6 +198,8 @@ if [ ${ENABLE_IP_ALIASES} = true ]; then
# Size of ranges allocated to each node. gcloud alpha supports only /32 and /24.
# Size of ranges allocated to each node. gcloud alpha supports only /32 and /24.
IP_ALIAS_SIZE
=
${
KUBE_GCE_IP_ALIAS_SIZE
:-
/24
}
IP_ALIAS_SIZE
=
${
KUBE_GCE_IP_ALIAS_SIZE
:-
/24
}
IP_ALIAS_SUBNETWORK
=
${
KUBE_GCE_IP_ALIAS_SUBNETWORK
:-${
INSTANCE_PREFIX
}
-subnet-default
}
IP_ALIAS_SUBNETWORK
=
${
KUBE_GCE_IP_ALIAS_SUBNETWORK
:-${
INSTANCE_PREFIX
}
-subnet-default
}
# Reserve the services IP space to avoid being allocated for other GCP resources.
SERVICE_CLUSTER_IP_SUBNETWORK
=
${
KUBE_GCE_SERVICE_CLUSTER_IP_SUBNETWORK
:-${
INSTANCE_PREFIX
}
-subnet-services
}
# NODE_IP_RANGE is used when ENABLE_IP_ALIASES=true. It is the primary range in
# NODE_IP_RANGE is used when ENABLE_IP_ALIASES=true. It is the primary range in
# the subnet and is the range used for node instance IPs.
# the subnet and is the range used for node instance IPs.
NODE_IP_RANGE
=
"
${
NODE_IP_RANGE
:-
10
.40.0.0/22
}
"
NODE_IP_RANGE
=
"
${
NODE_IP_RANGE
:-
10
.40.0.0/22
}
"
...
...
cluster/gce/config-test.sh
View file @
7c9b6e90
...
@@ -231,6 +231,8 @@ if [ ${ENABLE_IP_ALIASES} = true ]; then
...
@@ -231,6 +231,8 @@ if [ ${ENABLE_IP_ALIASES} = true ]; then
# Size of ranges allocated to each node. gcloud current supports only /32 and /24.
# Size of ranges allocated to each node. gcloud current supports only /32 and /24.
IP_ALIAS_SIZE
=
${
KUBE_GCE_IP_ALIAS_SIZE
:-
/24
}
IP_ALIAS_SIZE
=
${
KUBE_GCE_IP_ALIAS_SIZE
:-
/24
}
IP_ALIAS_SUBNETWORK
=
${
KUBE_GCE_IP_ALIAS_SUBNETWORK
:-${
INSTANCE_PREFIX
}
-subnet-default
}
IP_ALIAS_SUBNETWORK
=
${
KUBE_GCE_IP_ALIAS_SUBNETWORK
:-${
INSTANCE_PREFIX
}
-subnet-default
}
# Reserve the services IP space to avoid being allocated for other GCP resources.
SERVICE_CLUSTER_IP_SUBNETWORK
=
${
KUBE_GCE_SERVICE_CLUSTER_IP_SUBNETWORK
:-${
INSTANCE_PREFIX
}
-subnet-services
}
# NODE_IP_RANGE is used when ENABLE_IP_ALIASES=true. It is the primary range in
# NODE_IP_RANGE is used when ENABLE_IP_ALIASES=true. It is the primary range in
# the subnet and is the range used for node instance IPs.
# the subnet and is the range used for node instance IPs.
NODE_IP_RANGE
=
"
${
NODE_IP_RANGE
:-
10
.40.0.0/22
}
"
NODE_IP_RANGE
=
"
${
NODE_IP_RANGE
:-
10
.40.0.0/22
}
"
...
...
cluster/gce/util.sh
View file @
7c9b6e90
...
@@ -650,7 +650,7 @@ function kube-up() {
...
@@ -650,7 +650,7 @@ function kube-up() {
if
[[
${
KUBE_USE_EXISTING_MASTER
:-}
==
"true"
]]
;
then
if
[[
${
KUBE_USE_EXISTING_MASTER
:-}
==
"true"
]]
;
then
detect-master
detect-master
parse-master-env
parse-master-env
create-subnetwork
create-subnetwork
s
create-nodes
create-nodes
elif
[[
${
KUBE_REPLICATE_EXISTING_MASTER
:-}
==
"true"
]]
;
then
elif
[[
${
KUBE_REPLICATE_EXISTING_MASTER
:-}
==
"true"
]]
;
then
if
[[
"
${
MASTER_OS_DISTRIBUTION
}
"
!=
"gci"
&&
"
${
MASTER_OS_DISTRIBUTION
}
"
!=
"debian"
&&
"
${
MASTER_OS_DISTRIBUTION
}
"
!=
"ubuntu"
]]
;
then
if
[[
"
${
MASTER_OS_DISTRIBUTION
}
"
!=
"gci"
&&
"
${
MASTER_OS_DISTRIBUTION
}
"
!=
"debian"
&&
"
${
MASTER_OS_DISTRIBUTION
}
"
!=
"ubuntu"
]]
;
then
...
@@ -666,7 +666,7 @@ function kube-up() {
...
@@ -666,7 +666,7 @@ function kube-up() {
else
else
check-existing
check-existing
create-network
create-network
create-subnetwork
create-subnetwork
s
write-cluster-name
write-cluster-name
create-autoscaler-config
create-autoscaler-config
create-master
create-master
...
@@ -735,7 +735,7 @@ function create-network() {
...
@@ -735,7 +735,7 @@ function create-network() {
fi
fi
}
}
function
create-subnetwork
()
{
function
create-subnetwork
s
()
{
case
${
ENABLE_IP_ALIASES
}
in
case
${
ENABLE_IP_ALIASES
}
in
true
)
;;
true
)
;;
false
)
return
;;
false
)
return
;;
...
@@ -743,8 +743,8 @@ function create-subnetwork() {
...
@@ -743,8 +743,8 @@ function create-subnetwork() {
exit
1
;;
exit
1
;;
esac
esac
# Look for the
subnet, it must exist and have a secondary range
# Look for the
alias subnet, it must exist and have a secondary
# configured.
#
range
configured.
local
subnet
=
$(
gcloud beta compute networks subnets describe
\
local
subnet
=
$(
gcloud beta compute networks subnets describe
\
--project
"
${
PROJECT
}
"
\
--project
"
${
PROJECT
}
"
\
--region
${
REGION
}
\
--region
${
REGION
}
\
...
@@ -770,7 +770,6 @@ function create-subnetwork() {
...
@@ -770,7 +770,6 @@ function create-subnetwork() {
--region
${
REGION
}
\
--region
${
REGION
}
\
--range
${
NODE_IP_RANGE
}
\
--range
${
NODE_IP_RANGE
}
\
--secondary-range
"name=pods-default,range=
${
CLUSTER_IP_RANGE
}
"
--secondary-range
"name=pods-default,range=
${
CLUSTER_IP_RANGE
}
"
echo
"Created subnetwork
${
IP_ALIAS_SUBNETWORK
}
"
echo
"Created subnetwork
${
IP_ALIAS_SUBNETWORK
}
"
else
else
if
!
echo
${
subnet
}
|
grep
--quiet
secondaryIpRanges
${
subnet
}
;
then
if
!
echo
${
subnet
}
|
grep
--quiet
secondaryIpRanges
${
subnet
}
;
then
...
@@ -778,6 +777,31 @@ function create-subnetwork() {
...
@@ -778,6 +777,31 @@ function create-subnetwork() {
exit
1
exit
1
fi
fi
fi
fi
# Services subnetwork.
local
subnet
=
$(
gcloud beta compute networks subnets describe
\
--project
"
${
PROJECT
}
"
\
--region
${
REGION
}
\
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
2>/dev/null
)
if
[[
-z
${
subnet
}
]]
;
then
if
[[
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
!=
${
INSTANCE_PREFIX
}
-subnet-services
]]
;
then
echo
"
${
color_red
}
Subnetwork
${
NETWORK
}
:
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
does not exist
${
color_norm
}
"
exit
1
fi
echo
"Creating subnet for reserving service cluster IPs
${
NETWORK
}
:
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
"
gcloud beta compute networks subnets create
\
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
\
--description
"Automatically generated subnet for
${
INSTANCE_PREFIX
}
cluster. This will be removed on cluster teardown."
\
--project
"
${
PROJECT
}
"
\
--network
${
NETWORK
}
\
--region
${
REGION
}
\
--range
${
SERVICE_CLUSTER_IP_RANGE
}
echo
"Created subnetwork
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
"
else
echo
"Subnet
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
already exists"
fi
}
}
function
delete-firewall-rules
()
{
function
delete-firewall-rules
()
{
...
@@ -801,16 +825,13 @@ function delete-network() {
...
@@ -801,16 +825,13 @@ function delete-network() {
fi
fi
}
}
function
delete-subnetwork
()
{
function
delete-subnetwork
s
()
{
if
[[
${
ENABLE_IP_ALIASES
:-}
!=
"true"
]]
;
then
if
[[
${
ENABLE_IP_ALIASES
:-}
!=
"true"
]]
;
then
return
return
fi
fi
# Only delete automatically created subnets.
# Only delete automatically created subnets.
if
[[
${
IP_ALIAS_SUBNETWORK
}
!=
${
INSTANCE_PREFIX
}
-subnet-default
]]
;
then
if
[[
${
IP_ALIAS_SUBNETWORK
}
==
${
INSTANCE_PREFIX
}
-subnet-default
]]
;
then
return
fi
echo
"Removing auto-created subnet
${
NETWORK
}
:
${
IP_ALIAS_SUBNETWORK
}
"
echo
"Removing auto-created subnet
${
NETWORK
}
:
${
IP_ALIAS_SUBNETWORK
}
"
if
[[
-n
$(
gcloud beta compute networks subnets describe
\
if
[[
-n
$(
gcloud beta compute networks subnets describe
\
--project
"
${
PROJECT
}
"
\
--project
"
${
PROJECT
}
"
\
...
@@ -821,6 +842,20 @@ function delete-subnetwork() {
...
@@ -821,6 +842,20 @@ function delete-subnetwork() {
--region
${
REGION
}
\
--region
${
REGION
}
\
${
IP_ALIAS_SUBNETWORK
}
${
IP_ALIAS_SUBNETWORK
}
fi
fi
fi
if
[[
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
==
${
INSTANCE_PREFIX
}
-subnet-services
]]
;
then
echo
"Removing auto-created subnet
${
NETWORK
}
:
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
"
if
[[
-n
$(
gcloud beta compute networks subnets describe
\
--project
"
${
PROJECT
}
"
\
--region
${
REGION
}
\
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
2>/dev/null
)
]]
;
then
gcloud
--quiet
beta compute networks subnets delete
\
--project
"
${
PROJECT
}
"
\
--region
${
REGION
}
\
${
SERVICE_CLUSTER_IP_SUBNETWORK
}
fi
fi
}
}
# Assumes:
# Assumes:
...
@@ -1537,7 +1572,7 @@ function kube-down() {
...
@@ -1537,7 +1572,7 @@ function kube-down() {
"
${
NETWORK
}
-default-ssh"
\
"
${
NETWORK
}
-default-ssh"
\
"
${
NETWORK
}
-default-internal"
# Pre-1.5 clusters
"
${
NETWORK
}
-default-internal"
# Pre-1.5 clusters
delete-subnetwork
delete-subnetwork
s
if
[[
"
${
KUBE_DELETE_NETWORK
}
"
==
"true"
]]
;
then
if
[[
"
${
KUBE_DELETE_NETWORK
}
"
==
"true"
]]
;
then
delete-network
||
true
# might fail if there are leaked firewall rules
delete-network
||
true
# might fail if there are leaked firewall rules
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment