问题
I have an EC2 instance that I use for personal work & projects with very small amounts of traffic (portfolio, etc).
I thought it'd be really cool (although obviously overkill) to set up a dev cluster running my various projects using Minikube and to connect a domain name to this instance.
Setup
I have an Ingress controller that points to my service, with an IP address that is different than the host machine. I think it's somehow the IP address of the VM, but only accessible from the host machine.
I'd really like to use Ingress because I have a number of projects running with different domain names in use. Seems like the simple & correct solution based on my limited knowledge.
Problem
Not knowing much about k8s/networking, I don't know how to get external traffic visiting the elastic IP assigned to my instance to be directed to the Ingress controller
What I've tried
I was thinking that, since this is really only going to be used for dev purposes, that I could try using kubect port-forward ...
somehow to point to my Ingress controller. But this port-forward
reference from the official website says nothing about Ingress controllers.
Question
What is the most correct way to get external traffic into my cluster via an Ingress controller?
回答1:
Assuming this is not for real production workload I would suggest below approach
Instead of using minikube use kubeadm to install a single node kubernetes cluster on the EC2 instance.
Make sure to remove the master node taint so that workload pods can be scheduled on the master node meaning the same EC2 instance will host control plane pods as well as workload pods. Command for that is
kubectl taint nodes nodename node-role.kubernetes.io/master:NoSchedule-
Install nginx ingress controller and use
hostNetwork: true
in the deployment yaml. So nginx will listen to the EC2 instance's network on port80
and443
. Here is the doc on this.Create ingress resource and you can access any service via EC2 instances public IP address.
When you have budget for more EC2 instance you can add those as worker nodes to the cluster using
kubeadm join
.
Note: You can use free t2.micro
which is tier EC2 instance as worker nodes.
来源:https://stackoverflow.com/questions/62642774/interested-in-setting-up-k8s-cluster-on-ec2-instance-with-minikube-domain-name