代码之家  ›  专栏  ›  技术社区  ›  mon

K8s服务器错误(未找到):未找到deployments.apps“nginx”

  •  0
  • mon  · 技术社区  · 3 年前

    问题

    Coursera Google Cloud Fundamentals: Getting Started with Kubernetes Engine 有运行和公开pod的说明。演示视频显示它正在工作。

    enter image description here 然而,它导致了我执行中的错误。如何修复?

    kubectl run nginx --image=nginx:1.10.0
    kubectl expose deployment nginx --type LoadBalancer --port 80 
    ---
    Error from server (NotFound): deployments.apps "nginx" not found
    

    环境

    GCP k8s。

    $ kubectl version
    Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:45:37Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}
    Server Version: version.Info{Major:"1", Minor:"20+", GitVersion:"v1.20.8-gke.2100", GitCommit:"4cd085fda961821985d176d25b67445c1efb6ba1", GitTreeState:"clean", BuildDate:"2021-07-16T09:22:57Z", GoVersion:"go1.15.13b5", Compiler:"gc", Platform:"linux/amd64"}
    WARNING: version difference between client (1.22) and server (1.20) exceeds the supported minor version skew of +/-1
    
    1 回复  |  直到 3 年前
        1
  •  8
  •   mon    3 年前

    原因

    kubectl run 不创建 deployment .

    'Error from server (NotFound): deployments.extensions "nginx" not found' when exposing NodePort #31

    你用“kubectl run”创建了一个pod吗?如果是,则不会创建(至少)kubectl v1.18.2的部署,因此使用“kubectl create-deployment nginx--image=nginx:1.10.0”

    修理

    在中创建部署 Creating and exploring an nginx deployment 从YAML或运行 kubectl create deployment ... .

    $ kubectl create deployment nginx --image=nginx:1.12.0
    deployment.apps/nginx created
    
    $ kubectl expose deployment nginx --type LoadBalancer --port 80
    service/nginx exposed
    
    $ kubectl get services
    NAME         TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)        AGE
    kubernetes   ClusterIP      10.83.240.1    <none>           443/TCP        44m
    nginx        LoadBalancer   10.83.246.84   35.225.127.227   80:30825/TCP   60s