This repo installs 3 node Kubernetes cluster on AWS with 1 master and 2 worker
./packages.sh
python3 -m venv ansible
source /root/kubernates-ansible-aws/ansible/bin/activate
pip install pip --upgrade
pip install -r requirements.txt
aws configure OR EXPORT AWS_KEY_ID = XXXXXXXXXXXXX
EXPORT AWS_SECRET_KEY =XXXXXXXXXX
ansible-playbook -i inventory create-infra.yml
ansible -i ec2-k8.py worker --list | grep -v hosts | awk '{print $1 " worker"}' > files/hosts
ansible -i ec2-k8.py master --list | grep -v hosts | awk '{print $1 " master"}' >> files/hosts
Update host in distribute key playbook
ansible -i ec2-k8.py master --list | grep -v hosts | head -1 | awk '{print " - "$1}' >> distribute-key.yml
ansible -i ec2-k8.py worker --list | grep -v hosts | head -1 | awk '{print " - "$1}' >> distribute-key.yml
ansible-playbook -i inventory distribute-key.yml
export KUBE_API_SERVER_IP=ansible -i ec2-k8.py master --list | grep -v hosts | head -1 | awk '{print $1}'
sed -ir "s/kube_api_server: ChangeMe/kube_api_server: ${KUBE_API_SERVER_IP}/g" deploy-k8-ubuntu.yml
sed -ir "s/kube_api_server: ChangeMe/kube_api_server: ${KUBE_API_SERVER_IP}/g" add-node-ubuntu.yml
ansible -m ping -i ec2-k8.py master
ansible -m ping -i ec2-k8.py worker
ansible-playbook -i ec2-k8.py configue-ubuntu-infra.yml
ansible-playbook -v -i ec2-k8.py deploy-k8-ubuntu.yml
ansible -m shell -a "kubectl get no" -i ec2-k8.py master --become
ansible-playbook -v -i ec2-k8.py add-node-ubuntu.yml
ansible -m shell -a "kubectl get no" -i ec2-k8.py master --become
ansible -m shell -a "kubectl get po --all-namespaces" -i ec2-k8.py master --become
kubectl apply -f flask-app.yml
kubectl expose deployment flask-app --port=4080 --protocol=TCP --type=NodePort --name=my-service
kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 443/TCP 24m my-service NodePort 10.103.39.41 4080:32093/TCP 13s
http://<public_ip_of_node>:<service_port>
If you dont want public ip on worker node. configure the node behind the load balancer.