Created
January 30, 2021 19:22
-
-
Save maslick/dc52a3d70e88eea567fdd2c71eaea6ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Create 2 VMs on AWS | |
export MY_ACCESS_KEY_ID=…. | |
export MY_SECRET_ACCESS_KEY=…… | |
docker-machine create --driver amazonec2 \ | |
--amazonec2-access-key $MY_ACCESS_KEY_ID \ | |
--amazonec2-secret-key $MY_SECRET_ACCESS_KEY \ | |
--amazonec2-region eu-central-1 \ | |
--amazonec2-instance-type m5.large \ | |
k8s-master | |
docker-machine create --driver amazonec2 \ | |
--amazonec2-access-key $MY_ACCESS_KEY_ID \ | |
--amazonec2-secret-key $MY_SECRET_ACCESS_KEY \ | |
--amazonec2-region eu-central-1 \ | |
--amazonec2-instance-type m5.large \ | |
k8s-node | |
2. Install k8s via kubeadm on master node | |
docker-machine ssh k8s-master | |
sudo su - | |
sudo apt-get update && sudo apt-get install -y apt-transport-https curl | |
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - | |
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list | |
deb https://apt.kubernetes.io/ kubernetes-xenial main | |
EOF | |
sudo apt-get update | |
sudo apt-get install -y kubelet kubeadm kubectl | |
sudo apt-mark hold kubelet kubeadm kubectl | |
kubeadm init | |
mkdir -p $HOME/.kube | |
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config | |
sudo chown $(id -u):$(id -g) $HOME/.kube/config | |
3. Install k8s via kubeadm on the worker node (join cluster) | |
docker-machine ssh k8s-node | |
sudo su - | |
sudo apt-get update && sudo apt-get install -y apt-transport-https curl | |
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - | |
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list | |
deb https://apt.kubernetes.io/ kubernetes-xenial main | |
EOF | |
sudo apt-get update | |
sudo apt-get install -y kubelet kubeadm kubectl | |
sudo apt-mark hold kubelet kubeadm kubectl | |
kubeadm join 172.31.21.130:6443 --token [TOKEN….] --discovery-token-ca-cert-hash [SHA….] | |
4. Install network layer (weave) | |
docker-machine ssh k8s-master | |
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" | |
kubectl get nodes | |
5. Install ingress controller | |
docker-machine ssh k8s-master | |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.43.0/deploy/static/provider/baremetal/deploy.yaml | |
6. Create ALB | |
NGINX_NODE_PORT=$(kubectl get svc -n ingress-nginx ingress-nginx-controller -ojsonpath='{.spec.ports[?(@.name=="http")].nodePort}') | |
Add both k8s-master and k8s-node public IPs to ALB’s target group ($NGINX_NODE_PORT), set health checks /healthz | |
7. Create custom web app | |
kubectl create deploy web --image gcr.io/google-samples/hello-app:1.0 --port=8080 | |
kubectl expose deploy web --target-port 8080 | |
export DNS=webapp.k8s.maslick.tech | |
cat <<EOF | kubectl apply -f - | |
apiVersion: extensions/v1beta1 | |
kind: Ingress | |
metadata: | |
name: web | |
annotations: | |
nginx.ingress.kubernetes.io/rewrite-target: / | |
spec: | |
rules: | |
- host: $DNS | |
http: | |
paths: | |
- path: / | |
backend: | |
serviceName: web | |
servicePort: 8080 | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment