Implementing Kubernetes and Docker on OCI
Introduction
This was an assignment for Cloud Security class in semester 1, 2022. The requirements asked me to pack a web application into Docker and then deploy the service on the cloud using Kubernetes. The entire lab environment was built on OCI (Oracle Cloud Infrastructure). Here are my configuration notes and the pitfalls I stepped through to help take the easy way out when deploying services to OCI in the future.
This diary focuses on the deployment phase. Since OCI has some pre-defined iptables rules that can block communications between nodes, security lists also affect internal communication between VMs, even if they are in the same subnet. I needed to modify the iptables and security lists as below:
Pre-Configuration
iptables (controller & nodes)
## save existing rules |
Security Lists
For easy configuration, I opened everything, so security lists ended up with only three rules:
0.0.0.0/0; TCP; All ports0.0.0.0/0; UDP; All ports0.0.0.0/0; ICMP
But make sure that you refer to Kubernetes documentation and related CNI documentation to narrow down the open ports and IP ranges after implementation.
Configuration
After the pre-configuration part, we can start installing Kubernetes and Docker on all the VMs.
System updates (controller & nodes)
sudo apt update |
Docker (controller & nodes)
sudo apt -y install docker.io |
In daemon.json
{ |
Then run
sudo systemctl restart docker |
To check if Cgroup is systemd
sudo docker info | grep group |
K8S Installation (controller & nodes)
curl -s <https://packages.cloud.google.com/apt/doc/apt-key.gpg> | sudo apt-key add |
Post-Configuration
K8S init (controller)
sudo kubeadm init --pod-network-cidr=[CNI required range] --apiserver-advertise-address=[local IP address] |
--pod-network-cidr:
- flannel:
10.244.0.0/16 - weave:
10.32.0.0/12 - calico:
192.168.0.0/16
apply CNI
# flannel |
K8S join (nodes)
sudo kubeadm join 10.0.0.145:6443 --token rehcz9.67jf80xbe86oj9j1 \\ |
deployement.yml
kubectl apply -f deployement.yml |
service.yml
kubectl apply -f service.yml |
Check Docker and Kubelet Status
sudo systemctl status docker |
Monitor K8S Resources
watch kubectl get deployment,svc,pods,nodes -o wide --all-namespaces |
Command to Revert
K8S
sudo kubeadm reset |
Docker
sudo docker system prune -a |
!!! Pitfalls !!!
-
Everything is well configured; I can
curl localhost:30033from nodes orcurl [node_ip]:30033from the controller, but notcurl localhost:30033from the controller.This is because the iptables and security lists block the communication between
kube-proxies. Refers to the Pre-Configuration part. -
Timeout while joining controller from nodes.
This is highly due to improper configurations on security lists. We have to open TCP port 6443 for both ways.
-
Pods show
running, but theREADYstate is0/1for the DNS pod.This happens when I first implement flannel as my OCI, I finally figured out this issue is also related to iptables. The traffics are DROPPED by rules.
-
dial tcp 127.0.0.1:10248: connect: connection refusedwhen I runkubeadm init.This is because Docker
cgroupis notsystemd. -
failed to get config map: Unauthorisedwhile joining nodes to the controller.The token is invalid, run
sudo kubeadm token create --print-join-commandon the controller to create a new one. -
Port 10250 is in useThis is because
kubeletis using this port, runsudo systemctl restart kubeletorsudo kubeadm reset
References
- https://faun.pub/free-ha-multi-architecture-kubernetes-cluster-from-oracle-c66b8ce7cc37
- https://medium.com/platformer-blog/running-a-kubernetes-cluster-on-ubuntu-with-calico-9e372fb9175e
- https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
- https://github.com/flannel-io/flannel
- https://stackoverflow.com/a/60725618
- https://kubernetes.io/docs/reference/ports-and-protocols/
- https://kubernetes.io/docs/concepts/services-networking/service/
- https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
- https://docs.docker.com/engine/reference/commandline/dockerd/
- http://www.dest-unreach.org/socat/doc/socat.html#EXAMPLES
- https://blog.csdn.net/haveanybody/article/details/86494063
- https://stackoverflow.com/a/58491408
Implementing Kubernetes and Docker on OCI
https://wudiaries.com/2022/04/27/Implementing-Kubernetes-and-Docker-on-OCI/





