ssh 명령으로 heredoc을 사용하는 방법

ssh 명령으로 heredoc을 사용하는 방법

SSH를 통해 원격 컴퓨터에 연결하고 일련의 명령을 실행하는 bash 스크립트가 있습니다.

외부 스크립트의 heredoc이 올바르게 정렬되지 않은 것 같고 계속 오류가 발생합니다.

-bash: line 49: warning: here-document at line 6 delimited by end-of-file (wanted `MOD')

스크립트는 다음과 같습니다.

ssh -i "$master_private_key" "$master_username@$master_public_ip" << EOF
    # disable swap
    sudo swapoff -a
    sudo sed -i '/swap/ s/^/#/' /etc/fstab

    # setup the bridge for IPV4
    cat <<- MOD | sudo tee /etc/modules-load.d/k8s.conf
        overlay
        br_netfilter
    MOD
    sudo modprobe overlay
    sudo modprobe br_netfilter

    # sysctl params required by setup, params persist across reboots
    cat <<- MOD | sudo tee /etc/sysctl.d/k8s.conf
        net.bridge.bridge-nf-call-iptables = 1
        net.bridge.bridge-nf-call-ip6tables = 1
        net.ipv4.ip_forward = 1
    MOD

    # Apply sysclt parameters without reboot
    sudo sysctl --system

    sudo apt-get update && apt install docker.io -y
    sudo apt-get update 
    sudo apt-get install -y apt-transport-https ca-certificates curl
    sudo mkdir /etc/apt/keyrings
    sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
    echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    sudo apt-get update
    sudo apt-get install -y kubelet kubeadm kubectl
    sudo apt-mark hold kubelet kubeadm kubectl

    
    # initialize kubeadm on master
    kubeadm init --pod-network-cidir=192.168.0.0/16 --ignore-preflight-errors=all

    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config

    # install calico SDN
    kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml
    curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/custom-resources.yaml -O
    kubectl create -f custom-resources.yaml

    # Get the join command
    $JOIN_COMMAND=$(kubeadm token create --print-join-command)
    export $JOIN_COMMAND
    
EOF

누군가가 이것을 지적할 수 있기를 바랍니다.

관련 정보