Skip to content

Commit

Permalink
kubeadm: fix ubuntu support and tunnelhost for kvm
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Apr 27, 2020
1 parent f5def6e commit b9642fe
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
2 changes: 2 additions & 0 deletions kvirt/baseconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down
3 changes: 2 additions & 1 deletion kvirt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions kvirt/kubeadm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions kvirt/kubeadm/masters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion kvirt/kubeadm/masters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions kvirt/kubeadm/pre_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF >/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
18 changes: 13 additions & 5 deletions kvirt/openshift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit b9642fe

Please sign in to comment.