其他分享
首页 > 其他分享> > k8s 自定义informer

k8s 自定义informer

作者:互联网

 

it clone https://github.com/kairen/controller101.git

 

root@ubuntu:~/controller101# make
go build -ldflags="-s -w -X github.com/cloud-native-taiwan/controller101/pkg/version.version=v0.1.0" \
  -a -o out/controller cmd/main.go
go: downloading k8s.io/client-go v0.0.0-20191005115821-b1fd78950135
go: downloading github.com/spf13/pflag v1.0.3
go: downloading k8s.io/apimachinery v0.0.0-20191005115455-e71eb83a557c
go: downloading github.com/thoas/go-funk v0.4.0
go: downloading github.com/docker/go-connections v0.4.0
go: downloading github.com/pkg/errors v0.8.1
go: downloading golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc
go: downloading github.com/docker/go-units v0.4.0
go: downloading golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db
go: downloading k8s.io/api v0.0.0-20191005115622-2e41325d9e4b
go: downloading golang.org/x/time v0.0.0-20161028155119-f51c12702a4d
go: downloading k8s.io/utils v0.0.0-20190920012459-5008bf6f8cd6
go: downloading gopkg.in/yaml.v2 v2.2.4
go: downloading golang.org/x/crypto v0.0.0-20181025213731-e84da0312774
go: downloading golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a
go: downloading golang.org/x/sys v0.0.0-20190209173611-3b5209105503

 

 

root@ubuntu:~/controller101# go run cmd/main.go --kubeconfig=$HOME/.kube/config -v=2 --logtostderr  --vm-driver=docker  --lease-lock-namespace=default
I0708 11:46:39.735032   28294 leaderelection.go:242] attempting to acquire leader lease  default/controller101...
I0708 11:46:39.769316   28294 leaderelection.go:252] successfully acquired lease default/controller101
I0708 11:46:39.769415   28294 controller.go:77] Starting the controller
I0708 11:46:39.769439   28294 controller.go:78] Waiting for the informer caches to sync
E0708 11:46:39.771949   28294 reflector.go:153] pkg/mod/k8s.io/client-go@v0.0.0-20191005115821-b1fd78950135/tools/cache/reflector.go:105: Failed to list *v1alpha1.VirtualMachine: the server could not find the requested resource (get virtualmachines.cloudnative.tw)
E0708 11:46:40.773790   28294 reflector.go:153] pkg/mod/k8s.io/client-go@v0.0.0-20191005115821-b1fd78950135/tools/cache/reflector.go:105: Failed to list *v1alpha1.VirtualMachine: the server could not find the requested resource (get virtualmachines.cloudnative.tw)
E0708 11:46:41.775497   28294 reflector.go:153] pkg/mod/k8s.io/client-go@v0.0.0-20191005115821-b1fd78950135/tools/cache/reflector.go:105: Failed to list *v1alpha1.VirtualMachine: the server could not find the requested resource (get virtualmachines.cloudnative.tw)
E0708 11:46:42.777139   28294 reflector.go:153] pkg/mod/k8s.io/client-go@v0.0.0-20191005115821-b1fd78950135/tools/cache/reflector.go:105: Failed to list *v1alpha1.VirtualMachine: the server could not find the requested resource (get virtualmachines.cloudnative.tw)
E0708 11:46:43.778515   28294 reflector.go:153] pkg/mod/k8s.io/client-go@v0.0.0-20191005115821-b1fd78950135/tools/cache/reflector.go:105: Failed to list *v1alpha1.VirtualMachine: the server could not find the requested resource (get virtualmachines.cloudnative.tw)
E0708 11:46:44.779683   28294 reflector.go:153] pkg/mod/k8s.io/client-go@v0.0.0-20191005115821-b1fd78950135/tools/cache/reflector.go:105: Failed to list *v1alpha1.VirtualMachine: the server could not find the requested resource (get virtualmachines.cloudnative.tw)
E0708 11:46:45.781476   28294 reflector.go:153] pkg/mod/k8s.io/client-go@v0.0.0-20191005115821-b1fd78950135/tools/cache/reflector.go:105: Failed to list *v1alpha1.VirtualMachine: the server could not find the requested resource (get virtualmachines.cloudnative.tw)
E0708 11:46:46.782890   28294 reflector.go:153] pkg/mod/k8s.io/client-go@v0.0.0-20191005115821-b1fd78950135/tools/cache/reflector.go:105: Failed to list *v1alpha1.VirtualMachine: the server could not find the requested resource (get virtualmachines.cloudnative.tw)

 

 

root@ubuntu:~/kube-batch/pkg# cat <<EOF | kubectl apply -f -
> apiVersion: cloudnative.tw/v1alpha1
> kind: VirtualMachine
> metadata:
>   name: test-vm
> spec:
>   resource:
>     cpu: 2
>     memory: 4G
> EOF
virtualmachine.cloudnative.tw/test-vm createderror: unable to recognize "STDIN": no matches for kind "VirtualMachine" in version "cloudnative.tw/v1alpha1"
root@ubuntu:~/kube-batch/pkg# cd ~
root@ubuntu:~# cat<<EOF >vm.yaml
>  
> apiVersion: cloudnative.tw/v1alpha1
> kind: VirtualMachine
> metadata:
>   name: test-vm
> spec:
>   resource:
>     cpu: 2
>     memory: 4G
> EOF
root@ubuntu:~# kubectl apply -f vm.yaml 
error: unable to recognize "vm.yaml": no matches for kind "VirtualMachine" in version "cloudnative.tw/v1alpha1"
root@ubuntu:~# cat vm.yaml 
 
apiVersion: cloudnative.tw/v1alpha1
kind: VirtualMachine
metadata:
  name: test-vm
spec:
  resource:
    cpu: 2
    memory: 4G
root@ubuntu:~# 

 

标签:downloading,reflector,自定义,tw,cloudnative,go,informer,k8s,v0.0
来源: https://www.cnblogs.com/dream397/p/14985457.html