运行Kubernetes示例控制器

时间:2019-04-26 22:16:49

标签: kubernetes

我正在尝试通过链接https://github.com/kubernetes/sample-controller来运行Kubernetes示例控制器示例。我在Ubuntu 18.04系统上设置了存储库,并能够构建示例控制器包。 但是,当我尝试运行go软件包时,出现一些错误,无法调试该问题。有人可以帮我吗?

这是我遵循的步骤:

user@ubuntu-user:~$ go get k8s.io/sample-controller
user@ubuntu-user:~$ cd $GOPATH/src/k8s.io/sample-controller

这是我在运行控制器时遇到的错误:

user@ubuntu-user:~/go/src/k8s.io/sample-controller$ ./sample-controller -kubeconfig=$HOME/.kube/config
E0426 15:05:57.721696   31517 reflector.go:125] k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go:117: Failed to list *v1alpha1.Foo: the server could not find the requested resource (get foos.samplecontroller.k8s.io)

Kubectl版本:

user@ubuntu-user:~$ kubectl version 
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:02:58Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"```

2 个答案:

答案 0 :(得分:1)

我已转载您的问题。本教程中的命令顺序是错误的。

在这种情况下,由于缺少资源(samplecontroller),您收到此错误

$ ./sample-controller -kubeconfig=$HOME/.kube/config
E0430 12:55:05.089624  147744 reflector.go:125] k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go:117: Failed to list *v1alpha1.Foo: the server could not find the requested resource (get foos.samplecontroller.k8s.io)
^CF0430 12:55:05.643778  147744 main.go:74] Error running controller: failed to wait for caches to sync
goroutine 1 [running]:
k8s.io/klog.stacks(0xc0002feb00, 0xc000282200, 0x66, 0x1f5)
    /usr/local/google/home/user/go/src/k8s.io/klog/klog.go:840 +0xb1
k8s.io/klog.(*loggingT).output(0x2134040, 0xc000000003, 0xc0002e12d0, 0x20afafb, 0x7, 0x4a, 0x0)
    /usr/local/google/home/user/go/src/k8s.io/klog/klog.go:791 +0x303
k8s.io/klog.(*loggingT).printf(0x2134040, 0x3, 0x14720f2, 0x1c, 0xc0003c1f48, 0x1, 0x1)
    /usr/local/google/home/user/go/src/k8s.io/klog/klog.go:690 +0x14e
k8s.io/klog.Fatalf(...)
    /usr/local/google/home/user/go/src/k8s.io/klog/klog.go:1241
main.main()
    /usr/local/google/home/user/go/src/k8s.io/sample-controller/main.go:74 +0x3f5

您可以验证未创建此api

$ kubectl api-versions | grep sample
$ <emptyResult>

在教程中,您具有创建自定义资源定义

的命令
$ kubectl create -f artifacts/examples/crd.yaml
customresourcedefinition.apiextensions.k8s.io/foos.samplecontroller.k8s.io created

现在您可以搜索此CRD,它将在列表中。

$ kubectl api-versions | grep sample
samplecontroller.k8s.io/v1alpha1

下一步是创建Foo资源

$ kubectl create -f artifacts/examples/example-foo.yaml
foo.samplecontroller.k8s.io/example-foo created

那些命令还不会创建任何对象。

user@user:~/go/src/k8s.io/sample-controller$ kubectl get all
NAME                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   XX.XXX.XXX.XX   <none>        443/TCP   14d

所有资源将在您运行./sample-controller -kubeconfig=$HOME/.kube/config

之后创建
user@user:~/go/src/k8s.io/sample-controller$ ./sample-controller -kubeconfig=$HOME/.kube/config
user@user:~/go/src/k8s.io/sample-controller$ kubectl get all
NAME                               READY   STATUS    RESTARTS   AGE
pod/example-foo-6cbc69bf5d-8k59h   1/1     Running   0          43s

NAME                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.39.240.1   <none>        443/TCP   14d

NAME                          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/example-foo   1         1         1            1           43s

NAME                                     DESIRED   CURRENT   READY   AGE
replicaset.apps/example-foo-6cbc69bf5d   1         1         1       43s

正确的订单:

$ go get k8s.io/sample-controller
$ cd $GOPATH/src/k8s.io/sample-controller
$ go build -o sample-controller .
$ kubectl create -f artifacts/examples/crd.yaml
$ kubectl create -f artifacts/examples/example-foo.yaml
$ ./sample-controller -kubeconfig=$HOME/.kube/config
$ kubectl get deployments

答案 1 :(得分:0)

您是否从自述文件中运行了这两个命令?

# create a CustomResourceDefinition
kubectl create -f artifacts/examples/crd.yaml

# create a custom resource of type Foo
kubectl create -f artifacts/examples/example-foo.yaml