Marc Lameriks
1995年进入甲骨文工作,现在是Oracle SOA首席顾问,专注于Oracle Cloud、Kubernetes、Docker等方面。
我一直在研究minikube,因此出于训练和演示的原因,在我自己的Windows笔记本上已经装好合适的环境,该环境在Oracle VirtualBox设备中有Guest OS、Docker和Minikube。该demo环境使用Vagrantfile、脚本以及Kubernetes manifest(yaml)文件。那么,这一次我将使用k3s来进行demo。
在本文中,我将展示详细的操作步骤——借助Vagrant在Oracle VirtualBox设备中,将k3s和Kubernetes Dashboard一起安装到Ubuntu Guest OS上。
安装k3s
根据官网(k3s.io)的介绍,安装k3s的过程将不会花费很长时间:
curl -sfL https://get.k3s.io | sh -
# Check for Ready node,
takes maybe 30 seconds
k3s kubectl get node
根据文档,使用以下命令(以及环境变量INSTALL_K3S_VERSION)来指定从github下载的k3s的特定版本:
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.0.1 sh -
在设置我的demo环境之前,先来看看k3s的要求:
操作系统
K3s应该可以在所有Linux版本上运行。但是,k3s已在以下操作系统及其随后的非主要版本中进行了测试:
Ubuntu 16.04 (amd64)
Ubuntu 18.04 (amd64)
Raspbian Buster (armhf)
硬件设备
硬件需求根据deployment的大小进行扩展。此处概述了最低要求的建议:
RAM:512MB
CPU:1核
关于k3s的版本,我选择了撰写文章时的最新版本v1.0.1。
Vagrantfile
根据k3s对操作系统的要求,我使用了Vagrant Box搜索页面来搜索Ubuntu 18.04 Vagrant Box (for VirtualBox)。
选择ubuntu/bionic64
在我现有的demo环境中,我将Vagrantfile的内容改为:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.define "ubuntu_k3s" do |ubuntu_k3s|
config.vm.network "forwarded_port",
guest: 8001,
host: 8001,
auto_correct: true
config.vm.network "forwarded_port",
guest: 9110,
host: 9110,
auto_correct: true
config.vm.provider "virtualbox" do |vb|
vb.name = "Ubuntu k3s"
vb.memory = "8192"
vb.cpus = "1"
args = []
config.vm.provision "shell",
path: "scripts/k3s.sh",
args: args
end
end
end
在脚本目录中,我创建了一个文件k3s.sh,其内容如下:
#!/bin/bash
echo "**** Begin installing k3s"
#Install
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.0.1 sh -
echo "**** End installing k3s"
从Windows笔记本电脑上名为env的子目录中,打开Windows命令提示符(cmd)并键入:vagrant up
该命令根据您的Vagrantfile创建和配置Guest machine。
以下为输出(仅展示k3s的部分):
ubuntu_k3s: **** Begin installing k3s
…
ubuntu_k3s: **** End installing k3s
ubuntu_k3s: **** Begin installing k3s
…
ubuntu_k3s: **** End installing k3s
ubuntu_k3s: **** Begin installing k3s
…
ubuntu_k3s: **** End installing k3s
我发现配置shell脚本已经运行了很多次。由于我最近将vagrant升级到2.2.6,所以可能与升级有关。以下是我找到的解决方案:
该错误本身是由于您的配置块没有名称。如果您不希望它们运行两次,则可以通过给它一个类似的名称来修复它:
config.vm.provision “my shell script”, type: “shell”, ….
所以,我将Vagrantfile更改为:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.define "ubuntu_k3s" do |ubuntu_k3s|
config.vm.network "forwarded_port",
guest: 8001,
host: 8001,
auto_correct: true
config.vm.provider "virtualbox" do |vb|
vb.name = "Ubuntu k3s"
vb.memory = "8192"
vb.cpus = "1"
args = []
config.vm.provision "k3s shell script", type: "shell",
path: "scripts/k3s.sh",
args: args
end
end
end
为了停止正在运行的计算机并破坏其资源,我在Windows命令提示符处使用了以下命令:
vagrant destroy
会产生以下输出:
ubuntu_k3s: Are you sure you want to destroy the ‘ubuntu_k3s’ VM? [y/N] y
==> ubuntu_k3s: Forcing shutdown of VM…
==> ubuntu_k3s: Destroying VM and associated drives…
该命令将会停止正在运行的Vagrant管理的计算机,并销毁在计算机创建过程中创建的所有资源。运行此命令后,你的计算机应处于干净状态,就好像你之前从未创建过Guest machine一样。
再次从Windows笔记本电脑上名为env的子目录中,打开Windows命令提示符(cmd)并键入:vagrant up
关于ubuntu / bionic64的版本,输出如下:
==> ubuntu_k3s: Checking if box ‘ubuntu/bionic64’ version ‘20191218.0.0’ is up to date…
==> ubuntu_k3s: A newer version of the box ‘ubuntu/bionic64’ for provider ‘virtualbox’ is
==> ubuntu_k3s: available! You currently have version ‘20191218.0.0’. The latest is version
==> ubuntu_k3s: ‘20200107.0.0’. Run `vagrant box update` to update.
会产生以下输出(仅展示k3s的部分):
ubuntu_k3s: **** Begin installing k3s
ubuntu_k3s: [INFO] Using v1.0.1 as release
ubuntu_k3s: [INFO] Downloading hash https://github.com/rancher/k3s/releases/download/v1.0.1/sha256sum-amd64.txt
ubuntu_k3s: [INFO] Downloading binary https://github.com/rancher/k3s/releases/download/v1.0.1/k3s
ubuntu_k3s: [INFO] Verifying binary download
ubuntu_k3s: [INFO] Installing k3s to /usr/local/bin/k3s
ubuntu_k3s: [INFO] Creating /usr/local/bin/kubectl symlink to k3s
ubuntu_k3s: [INFO] Creating /usr/local/bin/crictl symlink to k3s
ubuntu_k3s: [INFO] Creating /usr/local/bin/ctr symlink to k3s
ubuntu_k3s: [INFO] Creating killall script /usr/local/bin/k3s-killall.sh
ubuntu_k3s: [INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh
ubuntu_k3s: [INFO] env: Creating environment file /etc/systemd/system/k3s.service.env
ubuntu_k3s: [INFO] systemd: Creating service file /etc/systemd/system/k3s.service
ubuntu_k3s: [INFO] systemd: Enabling k3s unit
ubuntu_k3s: Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service ? /etc/systemd/system/k3s.service.
ubuntu_k3s: [INFO] systemd: Starting k3s
ubuntu_k3s: **** End installing k3s
由于有关ubuntu / bionic64版本的警告,我在Windows命令提示符中使用了提到的命令:
vagrant box update
产生以下输出:
==> ubuntu_k3s: Checking for updates to ‘ubuntu/bionic64’
ubuntu_k3s: Latest installed version: 20191218.0.0
ubuntu_k3s: Version constraints:
ubuntu_k3s: Provider: virtualbox
==> ubuntu_k3s: Updating ‘ubuntu/bionic64’ with provider ‘virtualbox’ from version
==> ubuntu_k3s: ‘20191218.0.0’ to ‘20200107.0.0’…
==> ubuntu_k3s: Loading metadata for box ‘https://vagrantcloud.com/ubuntu/bionic64’
==> ubuntu_k3s: Adding box ‘ubuntu/bionic64’ (v20200107.0.0) for provider: virtualbox
ubuntu_k3s: Downloading: https://vagrantcloud.com/ubuntu/boxes/bionic64/versions/20200107.0.0/providers/virtualbox.box
ubuntu_k3s: Download redirected to host: cloud-images.ubuntu.com
ubuntu_k3s:
==> ubuntu_k3s: Successfully added box ‘ubuntu/bionic64’ (v20200107.0.0) for ‘virtualbox’!
我使用了vagrant ssh
连接到正在运行的VM并开始做一些事情。
接下来,我在Linux命令提示符上使用了以下命令:
kubectl get nodes
产生以下输出:
WARN[2020-01-12T13:36:33.705394309Z] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with –write-kubeconfig-mode to modify kube config permissions
error: error loading config file “/etc/rancher/k3s/k3s.yaml”: open /etc/rancher/k3s/k3s.yaml: permission denied
备注:
在k3s(k3s kubectl get node)的起始页上提到的命令会导致相同的错误消息。这是因为在此情况下,当前用户(通过whoami命令)是:vagrant
一旦安装了k3s,我将使用以下命令(也可以在文档中找到):
sudo kubectl get nodes
产生以下输出:
NAME STATUS ROLES AGE VERSION
ubuntu-bionic Ready master 10m v1.16.3-k3s.2
根据文档,将kubeconfig文件写入/etc/rancher/k3s/k3s.yaml,然后自动启动或重新启动服务。安装脚本将安装k3s和其他实用程序,例如kubectl、crictl、k3s-killall.sh和k3s-uninstall.sh。
接下来,我使用以下命令:
cd /etc/rancher/k3s
ls -latr
产生以下输出:
total 12
-rw——- 1 root root 1052 Jan 12 10:16 k3s.yaml
drwxr-xr-x 2 root root 4096 Jan 12 10:16 .
drwxr-xr-x 4 root root 4096 Jan 12 10:16 ..
接下来,我使用以下命令来查看k3s.yaml文件中的内容:
sudo cat k3s.yaml
产生以下输出:
apiVersion: v1
clusters:
– cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJWekNCL3FBREFnRUNBZ0VBTUFvR0NDcUdTTTQ5QkFNQ01DTXhJVEFmQmdOVkJBTU1HR3N6Y3kxelpYSjIKWlhJdFkyRkFNVFUzT0RneU5ERTVNekFlRncweU1EQXhNVEl4TURFMk16TmFGdzB6TURBeE1Ea3hNREUyTXpOYQpNQ014SVRBZkJnTlZCQU1NR0dzemN5MXpaWEoyWlhJdFkyRkFNVFUzT0RneU5ERTVNekJaTUJNR0J5cUdTTTQ5CkFnRUdDQ3FHU000OUF3RUhBMElBQk12b3V1YjZTR3N6UVl2LzVyb0lpSE5xbXZ0aUxub2gyQTZzR1hIQyt2OWQKSzkwTVlmV2J2bkozVFhyeEg2Mm5LTDhEU05wcmN4eC9rRXNXM2FpZTV3Q2pJekFoTUE0R0ExVWREd0VCL3dRRQpBd0lDcERBUEJnTlZIUk1CQWY4RUJUQURBUUgvTUFvR0NDcUdTTTQ5QkFNQ0EwZ0FNRVVDSUJSUmlrd0FPcjFVCmJtTlhOcEw3Y1cxaDhRSGg4QnZJQmJKc2RqdGU3Myt4QWlFQXROUG9MTjliVFZpYmxlYW5SNFpKcStKNUxDMmsKeUUwN2daWlk1NURlc25RPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
server: https://127.0.0.1:6443
name: default
contexts:
– context:
cluster: default
user: default
name: default
current-context: default
kind: Config
preferences: {}
users:
– name: default
user:
password: 1f0b266cfdd8e11a9af1a6e262b09746
username: admin
Kubectl配置
接下来,我们着重关注一下配置。
默认情况下,kubectl在$ HOME / .kube目录中查找名为config的文件。你可以通过设置KUBECONFIG环境变量或设置–kubeconfig标志来指定其他kubeconfig文件。
关于k3s kubectl命令,适用以下规则:
- 运行嵌入式kubectl CLI。如果未设置KUBECONFIG环境变量,它将在启动k3s服务器节点时自动尝试使用在/etc/rancher/k3s/k3s.yaml中创建的配置文件。
为了让没有root权限的用户使用具有特定配置的kubectl,根据我们之前得到的警告:
无法读取/etc/rancher/k3s/k3s.yaml,请使用–write-kubeconfig-mode启动服务器以修改kube配置权限
因此我们必须以特定的kubeconfig模式启动k3s服务器。我们可以使用k3s服务器选项write-kubeconfig-mode(客户端)以这种模式[$ K3S_KUBECONFIG_MODE]写入kubeconfig。
我看了有关使用环境变量K3S_KUBECONFIG_MODE的文档,并遇到以下示例:
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=”644″ sh -s –
关于chmod 644的说明:
Chmod 644(chmod a + rwx,u-x,g-wx,o-wx)设置权限,以便User(U) /Owner可以读取、写入但无法执行。群组(G)和其他人(O)可以读取、无法写入和执行。
在脚本目录中,我将文件k3s.sh更改为以下内容:
#!/bin/bash
echo "**** Begin installing k3s"
#Install
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.0.1 K3S_KUBECONFIG_MODE="644" sh -
echo "**** End installing k3s"
为了简便起见,从此博客开始,我将不再在vagrant up
命令之前提及vagrant destroy
命令。
从Windows笔记本电脑上名为env的子目录中,打开Windows命令提示符(cmd)并键入:vagrant up
产生以下输出(仅显示关于k3s的部分):
ubuntu_k3s: **** Begin installing k3s
ubuntu_k3s: [INFO] Using v1.0.1 as release
ubuntu_k3s: [INFO] Downloading hash https://github.com/rancher/k3s/releases/download/v1.0.1/sha256sum-amd64.txt
ubuntu_k3s: [INFO] Downloading binary https://github.com/rancher/k3s/releases/download/v1.0.1/k3s
ubuntu_k3s: [INFO] Verifying binary download
ubuntu_k3s: [INFO] Installing k3s to /usr/local/bin/k3s
ubuntu_k3s: [INFO] Creating /usr/local/bin/kubectl symlink to k3s
ubuntu_k3s: [INFO] Creating /usr/local/bin/crictl symlink to k3s
ubuntu_k3s: [INFO] Creating /usr/local/bin/ctr symlink to k3s
ubuntu_k3s: [INFO] Creating killall script /usr/local/bin/k3s-killall.sh
ubuntu_k3s: [INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh
ubuntu_k3s: [INFO] env: Creating environment file /etc/systemd/system/k3s.service.env
ubuntu_k3s: [INFO] systemd: Creating service file /etc/systemd/system/k3s.service
ubuntu_k3s: [INFO] systemd: Enabling k3s unit
ubuntu_k3s: Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service ? /etc/systemd/system/k3s.service.
ubuntu_k3s: [INFO] systemd: Starting k3s
ubuntu_k3s: **** End installing k3s
因此,一旦安装了k3s,我就使用vagrant ssh打开一个Linux命令提示符,在其中使用以下命令:
kubectl get nodes
产生以下输出:
NAME STATUS ROLES AGE VERSION
ubuntu-bionic Ready master 49s v1.16.3-k3s.2
接下来,我将使用以下命令:
kubectl get pods --all-namespaces
产生以下输出:
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system local-path-provisioner-58fb86bdfd-g68v5 1/1 Running 0 76s
kube-system metrics-server-6d684c7b5-4zrgx 1/1 Running 0 75s
kube-system coredns-d798c9dd-szfg7 1/1 Running 0 76s
kube-system helm-install-traefik-xg2zd 0/1 Completed 0 76s
kube-system svclb-traefik-frjb9 3/3 Running 0 32s
kube-system traefik-65bccdc4bd-rxlv4 1/1 Running 0 32s
使用命令:
cd /etc/rancher/k3s
ls -latr
产生输出:
total 12
-rw-r–r– 1 root root 1052 Jan 12 14:40 k3s.yaml
drwxr-xr-x 2 root root 4096 Jan 12 14:40 .
drwxr-xr-x 4 root root 4096 Jan 12 14:40 ..
现在,我们改变了k3s.yaml的权限。
Kubernetes Web UI (Dashboard)
现在,让我们尝试通过dashboard与Kubernetes集群进行交互。
默认情况下,Dashboard UI不会被部署。要部署它,请运行以下命令:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta4/aio/deploy/recommended.yaml
你可以通过运行以下命令来使用kubectl命令行工具访问Dashboard:
kubectl proxy
Kubectl将在以下位置提供dashboard:
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
只能从执行命令的计算机上访问UI。有关更多选项,请参见kubectl proxy –help。
由于演示环境的设置,简单地使用kubectl代理是行不通的,所以我再次使用:
kubectl proxy --address='0.0.0.0' /dev/null &
在脚本目录中,我创建了一个包含以下内容的文件dashboard.sh:
#!/bin/bash
echo "**** Begin preparing dashboard"
echo "**** Install Kubernetes Dashboard"
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta4/aio/deploy/recommended.yaml
kubectl proxy --address='0.0.0.0' /dev/null &
echo "**** End preparing dashboard"
我将Vagrantfile的内容更改为:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.define "ubuntu_k3s" do |ubuntu_k3s|
config.vm.network "forwarded_port",
guest: 8001,
host: 8001,
auto_correct: true
config.vm.provider "virtualbox" do |vb|
vb.name = "Ubuntu k3s"
vb.memory = "8192"
vb.cpus = "1"
args = []
config.vm.provision "k3s shell script", type: "shell",
path: "scripts/k3s.sh",
args: args
args = []
config.vm.provision "dashboard shell script", type: "shell",
path: "scripts/dashboard.sh",
args: args
end
end
end
在Linux命令提示符中,输入:exit
然后,我打开一个Windows命令提示符(cmd)并键入:vagrant up
产生以下输出(仅显示有关dashboard的部分):
ubuntu_k3s: **** Begin preparing dashboard
ubuntu_k3s: **** Install Kubernetes Dashboard
ubuntu_k3s: namespace/kubernetes-dashboard created
ubuntu_k3s: serviceaccount/kubernetes-dashboard created
ubuntu_k3s: service/kubernetes-dashboard created
ubuntu_k3s: secret/kubernetes-dashboard-certs created
ubuntu_k3s: secret/kubernetes-dashboard-csrf created
ubuntu_k3s: secret/kubernetes-dashboard-key-holder created
ubuntu_k3s: configmap/kubernetes-dashboard-settings created
ubuntu_k3s: role.rbac.authorization.k8s.io/kubernetes-dashboard created
ubuntu_k3s: clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
ubuntu_k3s: rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
ubuntu_k3s: clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
ubuntu_k3s: deployment.apps/kubernetes-dashboard created
ubuntu_k3s: service/dashboard-metrics-scraper created
ubuntu_k3s: deployment.apps/dashboard-metrics-scraper created
ubuntu_k3s: **** End preparing dashboard
在Linux命令提示符上,我使用了以下命令:
kubectl get pods --all-namespaces
产生以下输出:
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system local-path-provisioner-58fb86bdfd-g68v5 1/1 Running 0 13m
kube-system metrics-server-6d684c7b5-4zrgx 1/1 Running 0 13m
kube-system coredns-d798c9dd-szfg7 1/1 Running 0 13m
kube-system helm-install-traefik-xg2zd 0/1 Completed 0 13m
kube-system svclb-traefik-frjb9 3/3 Running 0 12m
kube-system traefik-65bccdc4bd-rxlv4 1/1 Running 0 12m
kubernetes-dashboard dashboard-metrics-scraper-566cddb686-5wvcx 1/1 Running 0 9m38s
kubernetes-dashboard kubernetes-dashboard-7b5bf5d559-tn4rh 1/1 Running 0 9m38s
在浏览器上我输入以下URL:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
显示以下界面:
因此我需要一个token。我找到了一个示例(和dashboard相关)来创建ServiceAccount和ClusterRoleBinding manifest文件。首先创建了一个服务用户,并且完成了对角色cluster-admin的角色绑定(该角色在k3s中默认不存在):
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
该示例还提供了有关如何获取允许我登录到dashboard的token的信息:
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
基于以上示例,我在yaml目录中添加了一个文件serviceaccount-k3s.yaml,内容如下:
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
我将以下内容添加到yaml目录中的文件clusterrolebinding-k3s.yaml:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
namespace: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
结果,命令kubectl -n kube-system get secret包含一长串密钥信息。因此,我想使用另一个命名空间,以便更轻松地确定允许我登录到dashboard的token。我选择使用命名空间kubernetes-dashboard,因为该命名空间是在安装Kubernetes dashboard时创建的。参见上面的输出。
在脚本目录中,我将文件dashboard.sh更改为以下内容:
#!/bin/bash
echo "**** Begin preparing dashboard"
echo "**** Install Kubernetes Dashboard"
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta4/aio/deploy/recommended.yaml
#Create Helm chart
echo "**** Create Helm chart"
cd /vagrant
cd helmcharts
rm -rf /vagrant/helmcharts/k3s-chart/*
helm create k3s-chart
rm -rf /vagrant/helmcharts/k3s-chart/templates/*
cp /vagrant/yaml/*k3s.yaml /vagrant/helmcharts/k3s-chart/templates
# Install Helm chart
cd /vagrant
cd helmcharts
echo "**** Install Helm chart k3s-chart"
helm install k3s-release ./k3s-chart
# Wait 30 seconds
echo "**** Waiting 30 seconds ..."
sleep 30
#List helm releases
echo "**** List helm releases"
helm list -d
#List secrets
echo "**** List secrets with namespace kubernetes-dashboard"
kubectl get secrets --namespace kubernetes-dashboard
echo "**** Describe secret with namespace kubernetes-dashboard"
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
kubectl proxy --address='0.0.0.0' /dev/null &
echo "**** End preparing dashboard"
因为现在使用的是Helm 3.0.2版,所以我需要进行一些更改。使用以下命令确定更改的版本:
helm version
产生输出:
version.BuildInfo{Version:”v3.0.2″, GitCommit:”19e47ee3283ae98139d98460de796c1be1e3975f”, GitTreeState:”clean”, GoVersion:”go1.13.5″}
使用helm install ./k3s-chart –name k3s-release导致以下结果:
Error: unknown flag: –name
因此,我将其更改为:helm install k3s-release ./k3s-chart
因为我想使用Helm,所以我将Vagrantfile的内容更改为:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.define "ubuntu_k3s" do |ubuntu_k3s|
config.vm.network "forwarded_port",
guest: 8001,
host: 8001,
auto_correct: true
config.vm.provider "virtualbox" do |vb|
vb.name = "Ubuntu k3s"
vb.memory = "8192"
vb.cpus = "1"
args = []
config.vm.provision "k3s shell script", type: "shell",
path: "scripts/k3s.sh",
args: args
args = []
config.vm.provision "helm shell script", type: "shell",
path: "scripts/helm.sh",
args: args
args = []
config.vm.provision "dashboard shell script", type: "shell",
path: "scripts/dashboard.sh",
args: args
end
end
end
我再次打开Windows命令提示符(cmd)并键入:vagrant up
产生以下输出(仅显示有关dashboard的部分):
ubuntu_k3s: **** Begin preparing dashboard
ubuntu_k3s: **** Install Kubernetes Dashboard
ubuntu_k3s: namespace/kubernetes-dashboard created
ubuntu_k3s: serviceaccount/kubernetes-dashboard created
ubuntu_k3s: service/kubernetes-dashboard created
ubuntu_k3s: secret/kubernetes-dashboard-certs created
ubuntu_k3s: secret/kubernetes-dashboard-csrf created
ubuntu_k3s: secret/kubernetes-dashboard-key-holder created
ubuntu_k3s: configmap/kubernetes-dashboard-settings created
ubuntu_k3s: role.rbac.authorization.k8s.io/kubernetes-dashboard created
ubuntu_k3s: clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
ubuntu_k3s: rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
ubuntu_k3s: clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
ubuntu_k3s: deployment.apps/kubernetes-dashboard created
ubuntu_k3s: service/dashboard-metrics-scraper created
ubuntu_k3s: deployment.apps/dashboard-metrics-scraper created
ubuntu_k3s: **** Create Helm chart
ubuntu_k3s: Creating k3s-chart
ubuntu_k3s: **** Install Helm chart k3s-chart
ubuntu_k3s: NAME: k3s-release
ubuntu_k3s: LAST DEPLOYED: Tue Jan 14 19:53:24 2020
ubuntu_k3s: NAMESPACE: default
ubuntu_k3s: STATUS: deployed
ubuntu_k3s: REVISION: 1
ubuntu_k3s: TEST SUITE: None
ubuntu_k3s: **** Waiting 30 seconds …
ubuntu_k3s: **** List helm releases
ubuntu_k3s: NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
ubuntu_k3s: k3s-release default 1 2020-01-14 19:53:24.329429114 +0000 UTC deployed k3s-chart-0.1.0 1.16.0
ubuntu_k3s: **** List secrets with namespace kubernetes-dashboard
ubuntu_k3s: NAME
ubuntu_k3s:
ubuntu_k3s:
ubuntu_k3s:
ubuntu_k3s:
ubuntu_k3s: TYPE
ubuntu_k3s:
ubuntu_k3s:
ubuntu_k3s:
ubuntu_k3s:
ubuntu_k3s: DATA AGE
ubuntu_k3s: default-token-l2nr4 kubernetes.io/service-account-token 3 34s
ubuntu_k3s: kubernetes-dashboard-token-54p9k kubernetes.io/service-account-token 3 34s
ubuntu_k3s: kubernetes-dashboard-certs Opaque 0 34s
ubuntu_k3s: admin-user-token-trfdn kubernetes.io/service-account-token 3 31s
ubuntu_k3s: kubernetes-dashboard-csrf Opaque 1 34s
ubuntu_k3s: kubernetes-dashboard-key-holder Opaque 2 34s
ubuntu_k3s: **** Describe secret with namespace kubernetes-dashboard
ubuntu_k3s: Name: admin-user-token-trfdn
ubuntu_k3s: Namespace: kubernetes-dashboard
ubuntu_k3s: Labels:
ubuntu_k3s: Annotations: kubernetes.io/service-account.name: admin-user
ubuntu_k3s: kubernetes.io/service-account.uid: b65dc46c-0833-4fcf-b833-cfec45139764
ubuntu_k3s:
ubuntu_k3s: Type: kubernetes.io/service-account-token
ubuntu_k3s:
ubuntu_k3s: Data
ubuntu_k3s: ====
ubuntu_k3s: token: eyJhbGciOiJSUzI1NiIsImtpZCI6IlhyREtIa21HdlhBQVd2Nm9kTGtJU3RUTnlWWTNJaHI2blNPb3J5eWRwR2cifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXRyZmRuIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJiNjVkYzQ2Yy0wODMzLTRmY2YtYjgzMy1jZmVjNDUxMzk3NjQiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.bJBCZmV7oIUuljz9-I1oO71js-mAOZHc4wLaUwPayYAqAzx_kTM_oFwSEBtieFxmwYP2CTP2QJZM6G8OBGvLyUiQyRumaTavFo51Rh-eW9wSXO24p6Sf7BdQRaJsjS4lnInDGd1Ksrv-Az6LI10rrIJXHgI7jz1wNmSdSqk3OHGXgioKZL0qjlrwgS6UviTe-0geMFxvdGUogUWvShmQkR-sGRSfACYX8-RZdFSc3wRWsoIVo_4NME-q8uNm79BaP5RbPAC-z-2amVHJQUUtgs_88pY-Qu-iiDqUpC823pHYkjB65w5RICjjqlKIrWqAptT35fBFSOfrUKf_Oy483A
ubuntu_k3s: ca.crt: 526 bytes
ubuntu_k3s: namespace: 20 bytes
ubuntu_k3s: **** End preparing dashboard
在笔记本电脑上的浏览器中,我输入了token的值(如上所示),然后单击“登录”按钮:
打开Kubernetes dashboard,并选择默认命名空间。
接下来,我点击到“节点”。在这里,你可以看到Kubernetes集群由一个节点组成。
最后,我将命名空间更改为kube-system,并导航到Pods,结果如下:
现在,本文的任务已经完成了!在本文中,我描述了如何使用Vagrant和shell脚本从头开始自动设置演示环境,包括在Oracle VirtualBox设备内的Ubuntu Guest OS之上的k3s、Helm和Kubernetes Dashboard。k3s确实是相对容易安装。下一步就可以开始实际使用它了。