Skip to content

Instantly share code, notes, and snippets.

@philips
Last active June 27, 2017 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philips/1b97028fe9bd3c096d2198c929e44331 to your computer and use it in GitHub Desktop.
Save philips/1b97028fe9bd3c096d2198c929e44331 to your computer and use it in GitHub Desktop.

Running a local Kubernetes API server on a local workstation based on an etcd snapshot can be useful for debugging, and understanding database backups. In a few simple steps this can be accomplished on Windows, Linux, or OSX.

First, gather up a backup of the etcd data directory. Generally this file is stored in /var/etcd or /var/lib/etcd or a backup server. Inside of this directory is a file called member/snap/db which can be used to generate a new data-dir that can run locally.

$ ETCDCTL_API=3 etcdctl snapshot restore kube-system-kube-etcd-0000/member/snap/db --name m1 --initial-cluster m1=http://localhost:2380 --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://localhost:2380 --skip-hash-check

Now, run etcd against the generated data directory

etcd --data-dir m1.etcd/

Finally, launch an API server that hits this etcd server running on localhost.

wget https://storage.googleapis.com/kubernetes-release/release/v1.7.0-rc.1/bin/linux/amd64/kube-apiserver
chmod +x kube-apiserver
./kube-apiserver --cert-dir ./kubernetes-temp --etcd-servers=http://localhost:2379 --service-cluster-ip-range 10.3.0.0/12

Now, curl http://localhost:8080/api/v1/events. Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment