diff --git a/kvirt/baseconfig.py b/kvirt/baseconfig.py index f58c1a022..7d55d68ed 100644 --- a/kvirt/baseconfig.py +++ b/kvirt/baseconfig.py @@ -233,6 +233,8 @@ def __init__(self, client=None, containerclient=None, debug=False, quiet=False): self.image = options.get('image', self.default['image']) self.tunnel = bool(options.get('tunnel', self.default['tunnel'])) self.tunnelhost = options.get('tunnelhost', self.default['tunnelhost']) + if self.tunnelhost is None and self.type == 'kvm': + self.tunnelhost = self.host self.tunnelport = options.get('tunnelport', self.default['tunnelport']) self.tunneluser = options.get('tunneluser', self.default['tunneluser']) self.insecure = bool(options.get('insecure', self.default['insecure'])) diff --git a/kvirt/config.py b/kvirt/config.py index 86e8e7e8b..4dbd6f72b 100644 --- a/kvirt/config.py +++ b/kvirt/config.py @@ -1804,7 +1804,8 @@ def wait(self, name, image=None): done = False oldoutput = '' while not done: - sshcmd = k.ssh(name, tunnel=self.tunnel, insecure=self.insecure, cmd=cmd) + sshcmd = k.ssh(name, tunnel=self.tunnel, tunnelhost=self.tunnelhost, tunnelport=self.tunnelport, + tunneluser=self.tunneluser, insecure=self.insecure, cmd=cmd) output = os.popen(sshcmd).read() if 'finished' in output: done = True diff --git a/kvirt/kubeadm/__init__.py b/kvirt/kubeadm/__init__.py index 573697875..0b8b5dbb9 100644 --- a/kvirt/kubeadm/__init__.py +++ b/kvirt/kubeadm/__init__.py @@ -43,10 +43,12 @@ def create(config, plandir, cluster, overrides): config.plan(cluster, inputfile='%s/masters.yml' % plandir, overrides=data, wait=True) source, destination = "/root/join.sh", "%s/join.sh" % clusterdir scpcmd = k.scp(firstmaster, user='root', source=source, destination=destination, tunnel=config.tunnel, + tunnelhost=config.tunnelhost, tunnelport=config.tunnelport, tunneluser=config.tunneluser, download=True, insecure=True) os.system(scpcmd) source, destination = "/etc/kubernetes/admin.conf", "%s/auth/kubeconfig" % clusterdir scpcmd = k.scp(firstmaster, user='root', source=source, destination=destination, tunnel=config.tunnel, + tunnelhost=config.tunnelhost, tunnelport=config.tunnelport, tunneluser=config.tunneluser, download=True, insecure=True) os.system(scpcmd) workers = data.get('workers', 0) diff --git a/kvirt/kubeadm/masters.sh b/kvirt/kubeadm/masters.sh index 98dd992fd..30d8c63e8 100644 --- a/kvirt/kubeadm/masters.sh +++ b/kvirt/kubeadm/masters.sh @@ -18,7 +18,7 @@ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documen {% elif sdn == 'weavenet' %} kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=`kubectl version | base64 | tr -d '\n'`" {% elif sdn == 'calico' %} -kubectl apply -f https://docs.projectcalico.org/v3.9/manifests/calico.yaml +kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml {% elif sdn == 'canal' %} kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/canal/rbac.yaml kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/canal/canal.yaml @@ -28,7 +28,8 @@ kubectl apply -f https://raw.githubusercontent.com/romana/romana/master/containe mkdir -p /root/.kube cp -i /etc/kubernetes/admin.conf /root/.kube/config chown root:root /root/.kube/config -IP=`ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'` +# IP=`ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'` +IP=`hostname -I | cut -f1 -d" "` TOKEN=`kubeadm token create --ttl 0` HASH=`openssl x509 -in /etc/kubernetes/pki/ca.crt -noout -pubkey | openssl rsa -pubin -outform DER 2>/dev/null | sha256sum | cut -d' ' -f1` CMD="kubeadm join $IP:6443 --token $TOKEN --discovery-token-ca-cert-hash sha256:$HASH" diff --git a/kvirt/kubeadm/masters.yml b/kvirt/kubeadm/masters.yml index 92d37df9f..af057cee1 100644 --- a/kvirt/kubeadm/masters.yml +++ b/kvirt/kubeadm/masters.yml @@ -39,8 +39,10 @@ {% if config_type == 'ovirt' %} - ovirt_fix.sh {% endif %} +{% if 'ubuntu' in image or 'xenial' in image or 'yaketty' in image or 'zesty' in image or 'artful' in image or 'bionic' in image or 'cosmic' in image %} - path: /etc/yum.repos.d/kubernetes.repo origin: kubernetes.repo +{% endif %} {% if nfs and number == 0 %} - nfs.yml - nfs.sh @@ -51,7 +53,7 @@ - l2-bridge.yml {% endif %} scripts: -{% if 'xenial' in image or 'yaketty' in image or 'zesty' in image or 'artful' in image or 'bionic' in image or 'cosmic' in image %} +{% if 'ubuntu' in image or 'xenial' in image or 'yaketty' in image or 'zesty' in image or 'artful' in image or 'bionic' in image or 'cosmic' in image %} - pre_ubuntu.sh {% else %} - pre.sh diff --git a/kvirt/kubeadm/pre_ubuntu.sh b/kvirt/kubeadm/pre_ubuntu.sh new file mode 100644 index 000000000..65c97f34b --- /dev/null +++ b/kvirt/kubeadm/pre_ubuntu.sh @@ -0,0 +1,12 @@ +apt-get update && apt-get install -y apt-transport-https curl wget +curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - +wget -P /root/ https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 +mv /root/jq-linux64 /usr/bin/jq +chmod u+x /usr/bin/jq +cat </etc/apt/sources.list.d/kubernetes.list +deb http://apt.kubernetes.io/ kubernetes-xenial main +EOF +apt-get update +apt-get install -y docker.io kubelet kubectl kubeadm +systemctl enable docker && systemctl start docker +systemctl enable kubelet && systemctl start kubelet diff --git a/kvirt/openshift/__init__.py b/kvirt/openshift/__init__.py index 216aee818..ff81165e0 100755 --- a/kvirt/openshift/__init__.py +++ b/kvirt/openshift/__init__.py @@ -433,11 +433,14 @@ def create(config, plandir, cluster, overrides): sleep(5) sleep(5) cmd = "iptables -F ; yum -y install httpd ; systemctl start httpd" - sshcmd = k.ssh(bootstrap_helper_name, user='root', tunnel=config.tunnel, insecure=True, cmd=cmd) + sshcmd = k.ssh(bootstrap_helper_name, user='root', tunnel=config.tunnel, + tunnelhost=config.tunnelhost, tunnelport=config.tunnelport, tunneluser=config.tunneluser, + insecure=True, cmd=cmd) os.system(sshcmd) source, destination = "%s/bootstrap.ign" % clusterdir, "/var/www/html/bootstrap" scpcmd = k.scp(bootstrap_helper_name, user='root', source=source, destination=destination, - tunnel=config.tunnel, download=False, insecure=True) + tunnel=config.tunnel, tunnelhost=config.tunnelhost, tunnelport=config.tunnelport, + tunneluser=config.tunneluser, download=False, insecure=True) os.system(scpcmd) sedcmd = 'sed "s@https://api-int.%s.%s:22623/config/master@http://%s/bootstrap@" ' % (cluster, domain, bootstrap_api_ip) @@ -467,11 +470,14 @@ def create(config, plandir, cluster, overrides): sleep(5) sleep(5) cmd = "iptables -F ; yum -y install httpd ; systemctl start httpd" - sshcmd = k.ssh(bootstrap_helper_name, user='root', tunnel=config.tunnel, insecure=True, cmd=cmd) + sshcmd = k.ssh(bootstrap_helper_name, user='root', tunnel=config.tunnel, + tunnelhost=config.tunnelhost, tunnelport=config.tunnelport, tunneluser=config.tunneluser, + insecure=True, cmd=cmd) os.system(sshcmd) source, destination = "%s/bootstrap.ign" % clusterdir, "/var/www/html/bootstrap" scpcmd = k.scp(bootstrap_helper_name, user='root', source=source, destination=destination, - tunnel=config.tunnel, download=False, insecure=True) + tunnel=config.tunnel, tunnelhost=config.tunnelhost, tunnelport=config.tunnelport, + tunneluser=config.tunneluser, download=False, insecure=True) os.system(scpcmd) sedcmd = 'sed "s@https://api-int.%s.%s:22623/config/master@' % (cluster, domain) sedcmd += 'http://%s-bootstrap-helper.%s.%s/bootstrap@ "' % (cluster, domain) @@ -486,7 +492,9 @@ def create(config, plandir, cluster, overrides): cmd = "cat /opt/registry/certs/domain.crt" pprint("Deploying disconnected vm %s" % disconnected_vm, color='blue') config.plan(cluster, inputfile='%s/disconnected' % plandir, overrides=overrides, wait=True) - cacmd = k.ssh(disconnected_vm, user='root', tunnel=config.tunnel, insecure=True, cmd=cmd) + cacmd = k.ssh(disconnected_vm, user='root', tunnel=config.tunnel, + tunnelhost=config.tunnelhost, tunnelport=config.tunnelport, tunneluser=config.tunneluser, + insecure=True, cmd=cmd) disconnected_ca = os.popen(cacmd).read() if 'ca' in overrides: overrides['ca'] += disconnected_ca