0

On my Server1, Server2 and Server3, I've installed PostgreSQL and Patroni, and on Server1 only, I've installed HAProxy and etcd. Server1 is acting as master db and Server2 and Server3 are acting as replica.

Since it is not a production setup, I'm trying to install kubernetes on Server1 and Server2, where Server1 will act as kmaster and Server2 will act as knode.

As etcd is already being used by Patroni and HaProxy, Kubeadm is throwing error.

root@Server1:# kubeadm init --apiserver-advertise-address=192.168.1.111 --pod-network-cidr=192.168.0.0/16
[init] Using Kubernetes version: v1.28.1
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR Port-2379]: Port 2379 is in use
    [ERROR Port-2380]: Port 2380 is in use
    [ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

The IP of my Server1 is 192.168.1.111 and I'm following this guide for setup, as it is my first time playing with K8s. Setting up using Minikube start is not giving any error, and everything is setup smoothly. But, manually setup is throwing errors. How should I modify kubeadm init command to ensure the use of etcd by both K8s and Patroni.

Veera Nagireddy
  • 1,656
  • 1
  • 3
  • 12
  • Using etcd for multiple purposes its not recommended. Please refer following documentation https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/#limiting-access-of-etcd-clusters – Nataraj Medayhal Aug 29 '23 at 18:04
  • @NatarajMedayhal I also searched a lot and reached the conclusion to use external etcd for my Kubernetes setup. Can you help me achieving the same, by sharing any guide or something else? – Amartya Sinha Aug 30 '23 at 04:30
  • Following urls has one of the option https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability/#external-etcd-nodes https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/setup-ha-etcd-with-kubeadm/ – Nataraj Medayhal Aug 30 '23 at 04:42
  • @NatarajMedayhal Ok, I'll give it a try and let you know. I have gone through the guide, and it should solve my issue. – Amartya Sinha Aug 30 '23 at 05:56
  • @Amartya Sinha, Feel free to update the status of the question, have you tried the **EDIT1** in the answer and the issue is resolved? – Veera Nagireddy Sep 01 '23 at 08:23

1 Answers1

0

Cause : You might have deleted the kubernetes node and you are trying to recreate it.

Solution : Remove the directory /var/lib/etcd, this will help to resolve your issue. Use the command: rm -rf /var/lib/etcd to delete the directory. (kubeadm reset does the same work).

Note: Try skipping preflight checks. It would be fixed with 1.15.1 (kubernetes patch releases).

EDIT1:

If you want to use external etcd for k8s, follow Sunho Song's Medium Blog on Configuration of the Kubernetes cluster with external ETCD for a lab environment, which may help to resolve your issue.

Veera Nagireddy
  • 1,656
  • 1
  • 3
  • 12
  • /var/lib/etcd is not empty because etcd service is already being used by patroni and haproxy. I found a new idea, but I do not know how to setup it. I am thinking of installing etcd in a docker container and expose some other port. And then create a config file and setup kubeadm init through that config file. I'm not able to achieve it. If you can help achieving this using external etcd (running on a docker container). It would be good. – Amartya Sinha Aug 29 '23 at 12:40
  • Actually I removed /var/lib/etcd and then did kubeadm reset. doing this is shutting down my db setup. So, I'm thinking of using external etcd for k8s. – Amartya Sinha Aug 29 '23 at 12:58
  • @Amartya Sinha, Refer **EDIT1** in the above answer related to your further query. – Veera Nagireddy Aug 30 '23 at 05:50
  • Sure, I'll update after giving this a try. – Amartya Sinha Aug 30 '23 at 06:00