From 834308e08fb1701d16389442c7cc81a43dbd6a33 Mon Sep 17 00:00:00 2001 From: Ivan Shvedunov Date: Mon, 16 Apr 2018 04:46:27 +0300 Subject: [PATCH] Update Kubernetes-in-Kubernetes example --- examples/README.md | 19 +++++++++++++++---- examples/k8s.yaml | 21 ++++++--------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/README.md b/examples/README.md index 9ff269306..e18d50fc8 100644 --- a/examples/README.md +++ b/examples/README.md @@ -42,13 +42,13 @@ kubectl create -f k8s.yaml Watch progress of the cluster setup via the VM console: ``` -kubectl attach k8s-0 +kubectl attach -it k8s-0 ``` After it's complete you can log into the master node: ``` -virtletctl ssh ubuntu@k8s-0 -- -i examples/vmkey +virtletctl ssh root@k8s-0 -- -i examples/vmkey ``` There you can wait a bit for k8s nodes and pods to become ready. @@ -56,10 +56,21 @@ You can list them using the following commands inside the VM: ``` kubectl get nodes -w +# Press Ctrl-C when all 3 nodes are present and Ready kubectl get pods --all-namespaces -o wide -w +# Press Ctrl-C when all the pods are ready +``` + +You can then deploy and test nginx on the inner cluster: + +``` +kubectl run nginx --image=nginx --expose --port 80 +kubectl get pods -w +# Press Ctrl-C when the pod is ready +kubectl run bbtest --rm --attach --image=docker.io/busybox --restart=Never -- wget -O - http://nginx ``` After that you can follow [the instructions](../deploy/real-cluster.md) to install Virtlet on -the cluster, but note that you'll have to disable KVM because nested -virtualization is not yet supported by Virtlet. +the cluster if you want, but note that you'll have to disable KVM +because nested virtualization is not yet supported by Virtlet. diff --git a/examples/k8s.yaml b/examples/k8s.yaml index e844be840..0a5c03a39 100644 --- a/examples/k8s.yaml +++ b/examples/k8s.yaml @@ -46,24 +46,17 @@ spec: #!/bin/bash set -u -e set -o pipefail - apt-get update - apt-get install -y --force-yes apt-transport-https curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - - apt-get update - apt-get install -y --force-yes docker.io - apt-get install -y --force-yes kubelet kubeadm kubectl kubernetes-cni jq - # TODO: client-ca-file -- /etc/kubernetes/pki/ca.crt - # XXX: misplaced --feature-gates=... option, but will do for now - sed -i 's/--authorization-mode=Webhook /--feature-gates=DynamicKubeletConfig=true /' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf + apt-get install -y docker.io kubelet kubeadm kubectl kubernetes-cni + sed -i 's/--cluster-dns=10\.96\.0\.10/--cluster-dns=10.97.0.10/' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf systemctl daemon-reload - # make k8s-NNN names resolvable - sed -i 's/^search /search k8s.default.svc.cluster.local default.svc.cluster.local svc.cluster.local cluster.local/' /etc/resolv.conf if [[ $(hostname) =~ -0$ ]]; then - kubeadm init --token adcb82.4eae29627dc4c5a6 --pod-network-cidr=10.200.0.0/16 --service-cidr=10.97.0.0/16 --apiserver-cert-extra-sans=127.0.0.1,localhost # master node + kubeadm init --token adcb82.4eae29627dc4c5a6 --pod-network-cidr=10.200.0.0/16 --service-cidr=10.97.0.0/16 --apiserver-cert-extra-sans=127.0.0.1,localhost export KUBECONFIG=/etc/kubernetes/admin.conf - kubectl apply -f "https://git.io/weave-kube-1.6" + export kubever=$(kubectl version | base64 | tr -d '\n') + kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever" while ! kubectl get pods -n kube-system -l k8s-app=kube-dns|grep ' 3/3'; do sleep 1 done @@ -73,9 +66,7 @@ spec: echo "Master setup complete." >&2 else # worker node - # FIXME: it should work without --node-name, but it doesn't - # (complains about empty node name) - kubeadm join --token adcb82.4eae29627dc4c5a6 --node-name=$(hostname) k8s-0:6443 + kubeadm join --token adcb82.4eae29627dc4c5a6 --discovery-token-unsafe-skip-ca-verification k8s-0.k8s:6443 echo "Node setup complete." >&2 fi users: