单AWS EC2 Ubuntu16.04实例部署K8s:主从节点同机可行性问询
Can I run Kubernetes master and worker nodes on a single AWS EC2 Ubuntu 16.04 instance?
Absolutely possible! Running both the Kubernetes control plane (master node) and worker node on a single EC2 instance is totally feasible, especially for development, testing, or small-scale proof-of-concept deployments like your Spring Boot microservices. Here's what you need to know:
Key Setup Steps
- Prepare the instance:
- First, disable swap (Kubernetes requires this to operate correctly):
sudo swapoff -a sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab - Ensure your Ubuntu 16.04 instance meets minimum resource requirements: at least 2 vCPUs and 2GB RAM (opt for more if you plan to run multiple Spring Boot pods alongside K8s components).
- First, disable swap (Kubernetes requires this to operate correctly):
- Install a container runtime:
Pick a compatible runtime like Docker (stick to Docker 19.03.x or newer for Ubuntu 16.04 to avoid Kubernetes compatibility gaps) or containerd. - Set up Kubernetes components:
Installkubeadm,kubelet, andkubectlfollowing Kubernetes' official Ubuntu 16.04 installation guidelines. - Initialize the control plane:
Run the initialization command (using Flannel's recommended CIDR as an example):
Follow the post-init instructions to configurekubeadm init --pod-network-cidr=10.244.0.0/16kubectlfor your user account. - Allow the master node to host workloads:
Master nodes are tainted by default to prevent pod scheduling. Remove this restriction with:kubectl taint nodes --all node-role.kubernetes.io/master- - Deploy a pod network plugin:
Install a plugin like Flannel or Calico to enable pod-to-pod communication. For Flannel:
(You can also download this manifest locally and apply it if you prefer to avoid direct external links.)kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Critical Considerations
- Not suitable for production: A single-node cluster has no high availability. If your EC2 instance fails, your entire Kubernetes cluster (and Spring Boot services) will go offline. This setup is only recommended for non-production use cases.
- Resource constraints: Kubernetes control plane components (apiserver, etcd, scheduler, controller-manager) will consume CPU and memory alongside your Spring Boot pods. Monitor resource usage closely to avoid performance bottlenecks.
- Ubuntu 16.04 end-of-life: Ubuntu 16.04 reached end-of-support in April 2021. Newer Kubernetes versions may not support it, and you won't receive security updates. If possible, upgrade to Ubuntu 18.04 or later for a more stable environment.
- Security best practices: Since the control plane and worker run on the same instance, configure your EC2 security group to only expose necessary ports (e.g., 6443 for
kube-apiserver, 22 for SSH) and restrict access to trusted IPs.
For your use case—deploying a Spring Boot microservice on a single EC2 instance for learning or testing—this setup works perfectly. Just keep the above limitations in mind as you proceed.
内容的提问来源于stack exchange,提问作者Mr.DevEng
相关产品推荐
相关产品推荐

