Minimalistic kubernetes cluster to get source ip in aws cloud provider
kops Version 1.7.1
kubernetes
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.3", GitCommit:"f0efb3cb883751c5ffdbe6d515f3cb4fbe7b7acd", GitTreeState:"clean", BuildDate:"2017-11-09T07:26:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.11", GitCommit:"b13f2fd682d56eab7a6a2b5a1cab1a3d2c8bdd55", GitTreeState:"clean", BuildDate:"2017-11-25T17:51:39Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Please follow instructions given here
- Install
kops
- Install
kubectl
- Setup AWS - You can either setup aws environment manually by following the instruction given in the docs or you can leave that to kops (I preferred
kops
taking care of that stuff) - Configure DNS
- Testing your DNS setup
dig ns subdomain.example.com
aws s3api create-bucket --bucket your-domain-com-state-store --region us-east-1
export AWS_ACCESS_KEY_ID=<access-key>
export AWS_SECRET_ACCESS_KEY=<secret-key>
export KUBERNETES_PROVIDER=aws;
export KOPS_STATE_STORE=s3://your-domain-com-state-store
export NAME=your.domain.com
export MASTER_SIZE=t2.micro;
export NODE_SIZE=t2.micro;
export NUM_NODES=2;
export NODE_ZONES=eu-central-1a,eu-central-1b;
export MASTER_ZONES=eu-central-1a;
export AWS_S3_REGION=eu-central-1;
kops create cluster \
--cloud=$KUBERNETES_PROVIDER \
--zones=$NODE_ZONES \
--master-zones=$MASTER_ZONES \
--node-count=$NUM_NODES \
--node-size=$NODE_SIZE \
--master-size=$MASTER_SIZE \
--associate-public-ip=true \
--name=$NAME \
--yes
kops update cluster ${NAME} --yes
kops rolling-update cluster
kubectl create -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes-dashboard/v1.5.0.yaml
kubectl apply -f namespace.yaml
kubectl apply -f default-backend.yaml
kubectl apply -f configmap.yaml
kubectl apply -f nginx-controller.yaml
Map your External IP that you have got from below command to some domain name.
kubectl get svc --namespace=nginx-ingress nginx-ingress
External IP from aws will be a DNS name. Create a CNAME record set in route53 under the hosted zone (in this case your.domain.com
) and copy this DNS name in value
field and save the record set.
eg: something.your.domain.com
kubectl apply -f source-ip-deploy.yaml
kubectl apply -f source-ip-svc.yaml
Replace host
in rules section of ingress.yaml
with your domain that you mapped earlier
kubectl apply -f ingress.yaml
For more information checkout kubernetes page
Annotate nginx-ingress service of type=LoadBalancer using below command
kubectl annotate service --namespace=nginx-ingress nginx-ingress service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
curl http://something.your.domain.com/test
check for x-real-ip
field in the response (its a private ip)
kops delete cluster $NAME --yes