This tutorial will walk you through building a Kubernetes cluster with Kops in AWS Beijing or NinXia Region.
Name | Support Kops Version | Support Kubernetes Version | Last Update |
---|---|---|---|
pahud/kops-bjs | 1.9.1 | 1.9.6 | June03, 2018 |
Prepare the AMI
Install Kops and Kubectl client on your laptop
Create a proxy server with gost in AWS N. Virginia Region
Create a proxy forwarder in AWS Beijing Region
Create the cluster with Kops
Check the latest AMI ID from Kops Images document and find the AMI ID in the global regions(e.g. N. Virginia).
However, as the China Beijing region already has latest CoreOS AMI, you can just check CoreOS official EC2 AMI page and select the AMI for cn-north-1
region, make sure you select the HVM
AMI type. For example, current AMI ID is ami-555a8438 (Container Linux 1745.5.0). Please note the latest AMI ID may change over time.
Region | CoreOS AMI |
---|---|
Beijing(cn-north-1) | ami-555a8438 |
NinXia(cn-northwest-1) | ami-06a0b464 |
click the button to create a proxy server with gost and AWS Fargate in any of the following regions.
Region | Launch Stack in VPC | Runtime |
---|---|---|
Oregon (us-west-2) | Fargate+ECS | |
N. Virginia (us-east-1) | Fargate+ECS |
Depending on which region you woud like to provision your Kops cluster, click the button below to create an internal http_proxy forwarder for your Kops cluster. This template will create one t2.micro EC2 behind ELB in your existing VPC as the proxy forwarder.
Region | Launch Stack in VPC | Runtime |
---|---|---|
Beijing (cn-north-1) | EC2+ELB | |
NinXia (cn-northwest-1) | EC2+ELB |
update create_cluster.sh
and modify the variables:
cluster_name='cluster.bjs.k8s.local'
ami='ami-xxxxxxxx'
vpcid='vpc-c1e040a5'
cluster_name : specify your cluster name. You can leave it as default. Make sure the cluster_name
ends with .k8s.local
so it will create gossip-based cluster without using Route53, which is not available in China Beijing region.
ami : AMI ID. See Prepare the AMI above.
vpcid: Your existing VPC ID, in which you would launch your Kubernetes cluster with Kops.
update env.config
export AWS_PROFILE='bjs'
export AWS_DEFAULT_REGION='cn-north-1'
export AWS_REGION=${AWS_DEFAULT_REGION}
export KOPS_STATE_STORE=s3://pahud-kops-state-store
-
AWS_PROFILE - make sure the profile name points to your AWS Beijing Region configuration. Check ~/.aws/config for details.
-
AWS_DEFAULT_REGION - specify cn-north-1 for Beijing Region.
-
KOPS_STATE_STORE - you need specify an empty S3 bucket for Kops state store, make sure you change the value and points to your S3 bucket in Beijing Region.
execute the script to create the cluster:
$ bash create_cluster.sh
edit your cluster
$ kops edit cluster cluster.bjs.k8s.local
paste the content below under the spec
section for the cluster. Make sure you set correct httpProxy host.
spec:
docker:
logDriver: ""
registryMirrors:
- https://registry.docker-cn.com
egressProxy:
httpProxy:
host: <host>
port: 8888
excludes: amazonaws.com.cn,amazonaws.cn,aliyun.cn,aliyuncs.com,registry.docker-cn.com
(you should be able to see your httpProxy host and port info in the output of the cloudformation in Beijing Region)
update the cluster with —yes
kops update cluster --name cluster.bjs.k8s.local --yes
After a few minutes(typically 8-15min), you can validate the cluster like this:
$ kops validate cluster
Using cluster from kubectl context: cluster.bjs.k8s.local
Validating cluster cluster.bjs.k8s.local
INSTANCE GROUPS
NAME ROLE MACHINETYPE MIN MAX SUBNETS
master-cn-north-1a-1 Master m3.medium 1 1 cn-north-1a
master-cn-north-1a-2 Master m3.medium 1 1 cn-north-1a
master-cn-north-1b-1 Master m3.medium 1 1 cn-north-1b
nodes Node m3.medium 2 2 cn-north-1a,cn-north-1b
NODE STATUS
NAME ROLE READY
ip-172-31-37-81.cn-north-1.compute.internal node True
ip-172-31-39-42.cn-north-1.compute.internal master True
ip-172-31-51-46.cn-north-1.compute.internal master True
ip-172-31-68-190.cn-north-1.compute.internal master True
ip-172-31-68-61.cn-north-1.compute.internal node True
Your cluster cluster.bjs.k8s.local is ready
Or get nodes list like this
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
ip-172-31-37-81.cn-north-1.compute.internal Ready node 15m v1.9.3
ip-172-31-39-42.cn-north-1.compute.internal Ready master 17m v1.9.3
ip-172-31-51-46.cn-north-1.compute.internal Ready master 16m v1.9.3
ip-172-31-68-190.cn-north-1.compute.internal Ready master 16m v1.9.3
ip-172-31-68-61.cn-north-1.compute.internal Ready node 15m v1.9.3
delete the cluster
$ kops delete cluster --name cluster.bjs.k8s.local --yes
And delete the two cloudformation stacks from N.Virginia
and Beijing
regions.
The approach provided above will not leverage any local mirror of artifacts. If you are interested to leverage local artifacts mirror including the gcr.io
docker hub mirror to accelerate the boostrapping, please check this table:
Region | Guide |
---|---|
Beijing(cn-north-1) | fastboot guide |
NinXia(cn-northwest-1) | fastboot guide |
Questions? check the FAQ list here.