Skip to content

Instantly share code, notes, and snippets.

@leanderjanssen
Last active September 12, 2018 15:08
Show Gist options
  • Save leanderjanssen/8c01e6984d2b707c4d77d28f34aa298c to your computer and use it in GitHub Desktop.
Save leanderjanssen/8c01e6984d2b707c4d77d28f34aa298c to your computer and use it in GitHub Desktop.
deploy centos7 docker vm
#!/bin/sh
set -xe
FQDN="node"
DOCKERURL=https://storebits.docker.com/ee/centos/sub-2df29a12-742a-461b-893c-9c1aca7aa714
USERPASS=DockerAmazic1805
# hostname
echo "$FQDN" > /etc/hostname
sed -i "1 c\\127.0.0.1 $FQDN localhost" /etc/hosts
echo "preserve_hostname: true" >> /etc/cloud/cloud.cfg
# debug aliases
echo "alias itail='tail -f /var/log/cloud-init-output.log'" >> /home/centos/.bashrc
echo "alias ilog='cat /var/log/cloud-init-output.log'" >> /home/centos/.bashrc
echo "alias iscript='sudo cat /var/lib/cloud/instance/user-data.txt'" >> /home/centos/.bashrc
echo "alias amiscript='sudo cat /var/log/AMI-setup.log'" >> /home/centos/.bashrc
# docker
echo "$DOCKERURL" > /etc/yum/vars/dockerurl
yum-config-manager --add-repo $DOCKERURL/centos/docker-ee.repo
yum-config-manager --enable docker-ee-stable-17.06
yum makecache fast
yum -y install docker-ee bash-completion
usermod -aG docker centos
systemctl start docker
systemctl enable docker.service
echo "source /usr/share/bash-completion/completions/docker" >> /home/centos/.bashrc
# compose
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# kubernetes
mkdir /etc/systemd/system/kubelet.service.d
cat <<'EOF' >> /etc/systemd/system/kubelet.service.d/05-custom.conf
[Service]
Environment="KUBELET_EXTRA_ARGS=--cgroup-driver=cgroupfs"
EOF
systemctl daemon-reload
cat <<'EOF' >> /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
cat <<'EOF' >> /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
setenforce 0
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet
echo "source <(kubectl completion bash)" >> /home/centos/.bashrc
# other utils
yum install -y gcc bridge-utils
# calicoctl
curl -L https://github.com/projectcalico/calicoctl/releases/download/v3.1.3/calicoctl > /usr/local/bin/calicoctl
chmod +x /usr/local/bin/calicoctl
mkdir -p /etc/calico
cat <<'EOF' >> /etc/calico/calicoctl.cfg
apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
datastoreType: "etcdv3"
etcdEndpoints: "http://10.96.232.136:6666"
EOF
# other utils - bake into AMI someday
yum -y install bridge-utils
# password authentication and ssh port
echo centos:$USERPASS | chpasswd
sed -i 's|[#]*PasswordAuthentication no|PasswordAuthentication yes|g' /etc/ssh/sshd_config
sed -i 's|[#]*Port 22|Port 22|g' /etc/ssh/sshd_config
service ssh restart
semanage port -a -t ssh_port_t -p tcp 22
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
service docker stop
cat <<'EOF' >> /etc/docker/daemon.json
{
"storage-driver": "overlay2"
}
EOF
service docker start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment