Streamline the etcd.service creation
With this, the need for `mv` and `sed` is eliminated, the only casualty is escaping the `\` in the heredoc and odd `"`. Perhaps the tradeoff is worth it.pull/35/head
parent
cd019aa31a
commit
46c4813972
|
@ -60,36 +60,6 @@ sudo mkdir -p /var/lib/etcd
|
||||||
Create the etcd systemd unit file:
|
Create the etcd systemd unit file:
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
cat > etcd.service <<"EOF"
|
|
||||||
[Unit]
|
|
||||||
Description=etcd
|
|
||||||
Documentation=https://github.com/coreos
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ExecStart=/usr/bin/etcd --name ETCD_NAME \
|
|
||||||
--cert-file=/etc/etcd/kubernetes.pem \
|
|
||||||
--key-file=/etc/etcd/kubernetes-key.pem \
|
|
||||||
--peer-cert-file=/etc/etcd/kubernetes.pem \
|
|
||||||
--peer-key-file=/etc/etcd/kubernetes-key.pem \
|
|
||||||
--trusted-ca-file=/etc/etcd/ca.pem \
|
|
||||||
--peer-trusted-ca-file=/etc/etcd/ca.pem \
|
|
||||||
--initial-advertise-peer-urls https://INTERNAL_IP:2380 \
|
|
||||||
--listen-peer-urls https://INTERNAL_IP:2380 \
|
|
||||||
--listen-client-urls https://INTERNAL_IP:2379,http://127.0.0.1:2379 \
|
|
||||||
--advertise-client-urls https://INTERNAL_IP:2379 \
|
|
||||||
--initial-cluster-token etcd-cluster-0 \
|
|
||||||
--initial-cluster etcd0=https://10.240.0.10:2380,etcd1=https://10.240.0.11:2380,etcd2=https://10.240.0.12:2380 \
|
|
||||||
--initial-cluster-state new \
|
|
||||||
--data-dir=/var/lib/etcd
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=5
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
EOF
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
```
|
||||||
export INTERNAL_IP=$(curl -s -H "Metadata-Flavor: Google" \
|
export INTERNAL_IP=$(curl -s -H "Metadata-Flavor: Google" \
|
||||||
http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip)
|
http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip)
|
||||||
|
@ -99,16 +69,35 @@ export INTERNAL_IP=$(curl -s -H "Metadata-Flavor: Google" \
|
||||||
export ETCD_NAME=$(hostname -s)
|
export ETCD_NAME=$(hostname -s)
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
|
||||||
sed -i s/INTERNAL_IP/$INTERNAL_IP/g etcd.service
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
```
|
||||||
sed -i s/ETCD_NAME/$ETCD_NAME/g etcd.service
|
sudo sh "cat > /etc/systemd/system/etcd.service <<EOF
|
||||||
```
|
[Unit]
|
||||||
|
Description=etcd
|
||||||
|
Documentation=https://github.com/coreos
|
||||||
|
|
||||||
```
|
[Service]
|
||||||
sudo mv etcd.service /etc/systemd/system/
|
ExecStart=/usr/bin/etcd --name $ETCD_NAME \\
|
||||||
|
--cert-file=/etc/etcd/kubernetes.pem \\
|
||||||
|
--key-file=/etc/etcd/kubernetes-key.pem \\
|
||||||
|
--peer-cert-file=/etc/etcd/kubernetes.pem \\
|
||||||
|
--peer-key-file=/etc/etcd/kubernetes-key.pem \\
|
||||||
|
--trusted-ca-file=/etc/etcd/ca.pem \\
|
||||||
|
--peer-trusted-ca-file=/etc/etcd/ca.pem \\
|
||||||
|
--initial-advertise-peer-urls https://$INTERNAL_IP:2380 \\
|
||||||
|
--listen-peer-urls https://$INTERNAL_IP:2380 \\
|
||||||
|
--listen-client-urls https://$INTERNAL_IP:2379,http://127.0.0.1:2379 \\
|
||||||
|
--advertise-client-urls https://$INTERNAL_IP:2379 \\
|
||||||
|
--initial-cluster-token etcd-cluster-0 \\
|
||||||
|
--initial-cluster etcd0=https://10.240.0.10:2380,etcd1=https://10.240.0.11:2380,etcd2=https://10.240.0.12:2380 \\
|
||||||
|
--initial-cluster-state new \\
|
||||||
|
--data-dir=/var/lib/etcd
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF"
|
||||||
```
|
```
|
||||||
|
|
||||||
Start etcd:
|
Start etcd:
|
||||||
|
|
Loading…
Reference in New Issue