# Create a KeyPair on AWS
$ aws ec2 create-key-pair --key-name 'kindkey' --query 'KeyMaterial' --output text > ./kind-key.pem
# Set the correct permissions for the SSH key
$ chmod 400 ./kind-key.pem
# Create an EC2 instance with the dependencies pre-installed.# (depending on the number of nodes you're gonna create, you might need # to provision a more powerful instance, which will cost you more as well. # In this case, set the 'InstanceType' parameter below)
aws cloudformation create-stack \
--stack-name kind \
--template-body file://ec2.yaml \
--parameters \
ParameterKey=InstanceType,ParameterValue=t2.micro \
ParameterKey=KeyName,ParameterValue=kindkey
# Break for a coffee!# Go there, you deserve (and CloudFormation needs time to provision the instance)# Get the public IP of the instance
$ aws cloudformation describe-stacks \
--stack-name kind \
--query 'Stacks[0].Outputs[0].OutputValue'# Access the instance
$ ssh -i ./kind-key.pem ec2-user@[instance public ip]
Experiment 1: single node cluster
# Create a simple cluster (1 master, without taints)
$ kind create cluster
# Load the Kubeconfig generated by Kind
$ export KUBECONFIG="$(kind get kubeconfig-path --name='kind')"# List the nodes in the cluster
$ kubectl get nodes -o wide
# List running Docker containers (acting as K8s nodes)
$ docker ps
# Get Master node external IP
MASTERIP=$(k get node -l node-role.kubernetes.io/master -o jsonpath={.items[*].status.addresses[?\(@.type==\"InternalIP\"\)].address})# Schedule a pod in the cluster + NodePort service
$ kubectl run nginx --image nginx --port 80 --labels "app=nginx" --restart=Never
$ kubectl create service nodeport nginx --tcp 80 --node-port 30080
# Access the pod
$ curl $MASTERIP:30080
# Cleanup
$ kubectl delete all -l app=nginx
$ kind delete cluster
Experiment 2: multi node cluster
# Create a multi node cluster (1 master + 2 workers)
$ cat > kind-config.yaml <<EOFapiVersion: kind.sigs.k8s.io/v1alpha3nodes:- role: control-plane- role: worker- role: workerEOF
$ kind create cluster --config kind-config.yaml
# Load the Kubeconfig generated by Kind
$ export KUBECONFIG="$(kind get kubeconfig-path --name='kind')"# List the nodes in the cluster# (take note of the master node INTERNAL-IP)
$ kubectl get nodes -o wide
# List running Docker containers (acting as K8s nodes)
$ docker ps
# Get Master node external IP
MASTERIP=$(k get node -l node-role.kubernetes.io/master -o jsonpath={.items[*].status.addresses[?\(@.type==\"InternalIP\"\)].address})# Schedule a deployment with 4 nginx pods + NodePort service
$ kubectl run nginx --image nginx --port 80 --labels "app=nginx" --replicas 4
$ kubectl create service nodeport nginx --tcp 80 --node-port 30080
# Check that pods are distributed across nodes
$ kubectl get po -l app=nginx -o wide
# Access the pod
$ curl $MASTERIP:30080
# Cleanup
$ kubectl delete all -l app=nginx
$ kind delete cluster