我开始学习kubernetes。我按照教程操作,但无法重现该步骤。我只需安装 kubectl 和 minikube,使用 docker 作为驱动程序启动 minikube 并运行 pod。
filip@filip-pc:~/Desktop$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-apache 1/1 Running 0 5h7m
my-nging 1/1 Running 0 4h59m
filip@filip-pc:~/Desktop$ kubectl scale --replicas=2 my-apache
error: the server doesn't have a resource type "my-apache"
filip@filip-pc:~/Desktop$ kubectl cluster-info
Kubernetes master is running at https://172.17.0.3:8443
KubeDNS is running at https://172.17.0.3:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
我可以找到一个 Pod,但我无法管理它。 如果我点击链接https://172.17.0.3:8443我收到错误
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "forbidden: User \"system:anonymous\" cannot get path \"/\"",
"reason": "Forbidden",
"details": {
},
"code": 403
}
我对此错误进行了简短的研究,但我发现的解决方案对我不起作用。 正如我提到的,我是 kubernetes 的新手,但我知道这是一个权限问题,但我使用的用户拥有权限
filip@filip-pc:~/Desktop$ kubectl auth can-i create deployments --namespace dev
yes
filip@filip-pc:~/Desktop$ kubectl auth can-i create deployments --namespace prod
yes
不知道您正在遵循哪个教程,也不确定您如何创建 pod,但如果它对他们有效而对您不起作用,那么问题可能在于您正在运行较新版本的 kubernetes。
使用
kubectl run ...
用于创建 pod 以及复制控制器。现在(自 1.18 起)它只创建一个 pod。您需要复制控制器(已弃用)、副本集或部署才能对其进行扩展。您无法扩展单个 Pod(Pod 资源没有可以扩展的副本概念 - 增加/减少)。
您可以将旧的运行命令替换为
kubectl create deployment myapache --image=httpd
并用
缩放它kubectl scale deployment myapache --replicas=2
它与使用旧的运行命令不完全相同,但很接近。