Compile etcd for use on Raspberry Pi

The most powerful feature of go, in my opinion, is the ability to cross-compile for other platforms. All Raspberry Pis are compatible with armv6, so we will use those settings.

git clone git@github.com:coreos/etcd.git
cd etcd


export GOOS="linux"
export GOARCH="arm"
export CGO_ENABLED=0
export GOARM=6


go build -o "bin/etcd" .

go build -o "bin/etcdctl" ./etcdctl

Systemd service script

cat << EOT > /usr/lib/systemd/system/etcd.service
[Unit]
Description=etcd service
After=network.target

[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd.conf
User=etcd
ExecStart=/opt/etcd/etcd
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOT

FILE: /etc/etcd.conf

cat << EOF > /etc/sysconfig/flanneld
FLANNEL_ETCD="http://192.168.122.173:4001"
FLANNEL_ETCD_KEY="/kubernetes-cluster/network"
EOF


# The official etcd ports are:
#   2379 for client requests
#   2380 for peer communication.
#
# Some legacy code and documentation still references ports 4001 and 7001


## Create configuration file for bootstrapping the etcd cluster

cat << EOF > /etc/etcd.conf
ETCD_INITIAL_CLUSTER="kuberpi1=http://10.10.100.10:2380,kuberpi2=http://10.10.100.20:2380,kuberpi3=http://10.10.100.30:2380"
# Initial cluster state ("new" or "existing").
# Set to new for all members present during initial bootstrapping. 
ETCD_INITIAL_CLUSTER_STATE=new
# Human-readable name for this member.
ETCD_NAME=$(hostname -s)
ETCD_DATA_DIR="/var/lib/etcd/$(hostname -s)"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_INITIAL_CLUSTER_TOKEN=kuberpi
ETCD_DEBUG=true
EOF

## Start etcd to bootstrap

systemctl status etcd.service
systemctl start  etcd.service
systemctl status etcd.service

## Create configuration file for normal etcd cluster operation

cat << EOF > /etc/etcd.conf
ETCD_INITIAL_CLUSTER="kuberpi1=http://10.10.100.10:2380,kuberpi2=http://10.10.100.20:2380,kuberpi3=http://10.10.100.30:2380"
# Initial cluster state ("new" or "existing").
# Set to new for all members present during initial bootstrapping. 
ETCD_INITIAL_CLUSTER_STATE=existing
# Human-readable name for this member.
ETCD_NAME=$(hostname -s)
ETCD_DATA_DIR="/var/lib/etcd/$(hostname -s)"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_INITIAL_CLUSTER_TOKEN=kuberpi
EOF

## Start etcd
categories: etcd | golang | raspberrypi | kubernetes | devops |