├── img ├── godday-ns.png └── fed-cluster.png ├── us-east ├── k ├── delete.sh └── create.sh ├── us-west ├── k ├── delete.sh └── create.sh ├── ap-northeast ├── k ├── delete.sh └── create.sh ├── patches ├── us-east-pod.yml ├── us-west-pod.yml └── kops-cluster-patch.yml ├── .gitignore ├── 0-create-hosted-domain.sh ├── 1-create-clusters.sh ├── 2-init-helm.sh ├── 5-join-us-east.sh ├── 6-join-us-west.sh ├── 4-join-ap-northeast.sh ├── 3-install-federation.sh ├── 14-create-nginx2-rsp.sh ├── dns-record.json ├── 7-create-fns.sh ├── 10-create-nginx-fsvc.sh ├── 12-create-nginx-domain-and-record.sh ├── 9-patch-nginx-pod.sh ├── 99-purge.sh ├── 13-create-nginx2-fdeploy.sh ├── 8-create-nginx-fdeploy.sh ├── .env.sample ├── 11-deploy-external-dns.sh └── README.md /img/godday-ns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kairen/aws-k8s-federation/HEAD/img/godday-ns.png -------------------------------------------------------------------------------- /img/fed-cluster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kairen/aws-k8s-federation/HEAD/img/fed-cluster.png -------------------------------------------------------------------------------- /us-east/k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | kubectl --context=${US_EAST_CONTEXT} $@ 7 | -------------------------------------------------------------------------------- /us-west/k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | kubectl --context=${US_WEST_CONTEXT} $@ 7 | -------------------------------------------------------------------------------- /ap-northeast/k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | kubectl --context=${AP_NORTHEAST_CONTEXT} $@ 7 | -------------------------------------------------------------------------------- /patches/us-east-pod.yml: -------------------------------------------------------------------------------- 1 | spec: 2 | containers: 3 | - name: nginx 4 | image: kairen/nginx:magic 5 | 6 | -------------------------------------------------------------------------------- /patches/us-west-pod.yml: -------------------------------------------------------------------------------- 1 | spec: 2 | containers: 3 | - name: nginx 4 | image: kairen/nginx:slowpoke 5 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | dns-record.json-d 3 | .env 4 | fed-controller-patch.yml 5 | 6 | # ignore all files generated by JetBrains tools 7 | .idea 8 | -------------------------------------------------------------------------------- /0-create-hosted-domain.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | aws route53 create-hosted-zone \ 7 | --name ${DOMAIN_NAME} \ 8 | --caller-reference $(date '+%Y-%m-%d-%H:%M') 9 | -------------------------------------------------------------------------------- /1-create-clusters.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | # Start to create k8s cluster on aws 7 | ./ap-northeast/create.sh 8 | ./us-east/create.sh 9 | ./us-west/create.sh 10 | -------------------------------------------------------------------------------- /us-east/delete.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | kops delete cluster \ 7 | --name=${US_EAST_CONTEXT} \ 8 | --state=s3://${US_EAST_BUCKET_NAME} --yes 9 | 10 | aws s3 rb s3://${US_EAST_BUCKET_NAME} --force 11 | -------------------------------------------------------------------------------- /us-west/delete.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | kops delete cluster \ 7 | --name=${US_WEST_CONTEXT} \ 8 | --state=s3://${US_WEST_BUCKET_NAME} --yes 9 | 10 | aws s3 rb s3://${US_WEST_BUCKET_NAME} --force 11 | -------------------------------------------------------------------------------- /ap-northeast/delete.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | kops delete cluster \ 7 | --name=${AP_NORTHEAST_CONTEXT} \ 8 | --state=s3://${AP_NORTHEAST_BUCKET_NAME} --yes 9 | 10 | aws s3 rb s3://${AP_NORTHEAST_BUCKET_NAME} --force 11 | -------------------------------------------------------------------------------- /2-init-helm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | # Switch to master cluster 7 | kubectl config use-context ${FED_CONTEXT} 8 | 9 | # Create RBAC for Helm 10 | kubectl -n kube-system create sa tiller 11 | kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller 12 | helm init --service-account tiller 13 | -------------------------------------------------------------------------------- /5-join-us-east.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | # Switch to the fed cluster context 7 | kubectl config use-context ${FED_CONTEXT} 8 | 9 | # Join the us-east cluster to the Federation 10 | kubefedctl join us-east \ 11 | --host-cluster-context=${AP_NORTHEAST_CONTEXT} \ 12 | --cluster-context=${US_EAST_CONTEXT} \ 13 | --v=2 14 | 15 | # Check cluster by kubectl 16 | kubectl -n kube-federation-system describe kubefedclusters us-east -------------------------------------------------------------------------------- /6-join-us-west.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | # Switch to the fed cluster context 7 | kubectl config use-context ${FED_CONTEXT} 8 | 9 | # Join the us-west cluster to the Federation 10 | kubefedctl join us-west \ 11 | --host-cluster-context=${AP_NORTHEAST_CONTEXT} \ 12 | --cluster-context=${US_WEST_CONTEXT} \ 13 | --v=2 14 | 15 | # Check cluster by kubectl 16 | kubectl -n kube-federation-system describe kubefedclusters us-west -------------------------------------------------------------------------------- /4-join-ap-northeast.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | # Switch to the fed cluster context 7 | kubectl config use-context ${FED_CONTEXT} 8 | 9 | # Join the ap-northeast cluster to the Federation 10 | kubefedctl join ap-northeast \ 11 | --host-cluster-context=${AP_NORTHEAST_CONTEXT} \ 12 | --cluster-context=${AP_NORTHEAST_CONTEXT} \ 13 | --v=2 14 | 15 | # Check cluster by kubectl 16 | kubectl -n kube-federation-system describe kubefedclusters ap-northeast -------------------------------------------------------------------------------- /3-install-federation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | # Switch to master cluster 7 | kubectl config use-context ${FED_CONTEXT} 8 | 9 | # Deploy the Federation control plane to the host cluster 10 | git clone https://github.com/kubernetes-sigs/kubefed.git -b v0.1.0-rc2 11 | cd kubefed 12 | 13 | helm install charts/kubefed \ 14 | --name kubefed \ 15 | --namespace kube-federation-system \ 16 | --set controllermanager.tag=v0.1.0-rc2 17 | 18 | # Remove unnecessary files 19 | cd ../ 20 | rm -rf kubefed 21 | 22 | kubectl -n kube-federation-system get po -o wide -------------------------------------------------------------------------------- /14-create-nginx2-rsp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | # Switch to the fed cluster context 7 | kubectl config use-context ${FED_CONTEXT} 8 | 9 | # Create a nginx2 rsp 10 | cat < Federation v2 can be deployed to and manage clusters running Kubernetes `v1.11` or greater. 18 | 19 | * [aws](https://aws.amazon.com/cli/?nc1=h_ls): The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. 20 | * We will be using Amazon AWS as the IaaS provider: 21 | * IAM: Provide identity and access management. 22 | * EC2: The Kubernetes cluster instances. 23 | * ELB: Kubernetes service load balancer. 24 | * Route53: Public domain for Kubernetes API, Service, ..., etc. 25 | * S3: Store Kops state. 26 | * VPC: Provide cluster network. 27 | * Godaddy domain name or register from Route53 28 | 29 | ## Quick Start 30 | For the execution of the labs, you need set your env in `.env` file: 31 | ```sh 32 | $ cp .env.sample .env 33 | $ vim .env 34 | ``` 35 | 36 | First create a hostedzone using `0-create-hosted-domain.sh`: 37 | ```sh 38 | $ ./0-create-hosted-domain.sh 39 | # output like this 40 | { 41 | "HostedZone": { 42 | "ResourceRecordSetCount": 2, 43 | "CallerReference": "2018-04-19-11:24", 44 | "Config": { 45 | "PrivateZone": false 46 | }, 47 | "Id": "/hostedzone/Z363YQ27EUQU4S", 48 | "Name": "k8s.xxxx.com." 49 | }, 50 | "DelegationSet": { 51 | "NameServers": [ 52 | "ns-431.awsdns-49.org", 53 | "ns-1341.awsdns-00.com", 54 | "ns-134.awsdns-42.co.uk", 55 | "ns-1131.awsdns-62.net" 56 | ] 57 | }, 58 | "Location": "https://route53.amazonaws.com/2013-04-01/hostedzone/Z363YQ27EUQU4S", 59 | "ChangeInfo": { 60 | "Status": "PENDING", 61 | "SubmittedAt": "2018-04-19T03:24:17.638Z", 62 | "Id": "/change/CTCT89X4F01LM" 63 | } 64 | } 65 | 66 | $ aws route53 list-hosted-zones 67 | ``` 68 | 69 | Add `NameServers` into Godaddy, like this: 70 | 71 | ![](/img/godday-ns.png) 72 | 73 | Now follow the scripts to setup your federation cluster. 74 | -------------------------------------------------------------------------------- /us-west/create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .env 4 | set -eux 5 | 6 | aws s3 mb s3://${US_WEST_BUCKET_NAME} --region ${US_WEST_REGION} 7 | 8 | cat <