kubernetes samplecontroller 编译部署测试

1 实验

1.1 下载编译

git clone相关的project

https://github.com/kubernetes/sample-controller.git

注意,国内golang下载依赖比较慢,选择使用ali的proxy

export GOPROXY=https://mirrors.aliyun.com/goproxy/
mkdir /root/gowork 
export GOPATH=/root/gowork/ 
cd /root/gowork/
git clone https://github.com/kubernetes/sample-controller.git
go build -v -o samplecontroller

1.2 运行controller

[vagrant@node1 sample-controller]$ ./sample-controller -kubeconfig /etc/kubernetes/admin.conf 
F0806 15:48:12.736121   14843 main.go:49] Error building kubeconfig: error loading config file "/etc/kubernetes/admin.conf": open /etc/kubernetes/admin.conf: permission denied
goroutine 1 [running]:
k8s.io/klog/v2.stacks(0xc000010001, 0xc000442000, 0xb0, 0x105)
        /home/mayi/workspace/duduai/gobackend/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:996 +0xb8
k8s.io/klog/v2.(*loggingT).output(0x21aec20, 0xc000000003, 0x0, 0x0, 0xc0003dce00, 0x210a00a, 0x7, 0x31, 0x0)
        /home/mayi/workspace/duduai/gobackend/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:945 +0x19d
k8s.io/klog/v2.(*loggingT).printf(0x21aec20, 0x3, 0x0, 0x0, 0x156ab4c, 0x1d, 0xc0000c1f68, 0x1, 0x1)
        /home/mayi/workspace/duduai/gobackend/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:733 +0x17b
k8s.io/klog/v2.Fatalf(...)
        /home/mayi/workspace/duduai/gobackend/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:1456
main.main()
        /home/mayi/workspace/github/sample-controller/main.go:49 +0x62f

goroutine 6 [chan receive]:
k8s.io/klog/v2.(*loggingT).flushDaemon(0x21aec20)
        /home/mayi/workspace/duduai/gobackend/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:1131 +0x8b
created by k8s.io/klog/v2.init.0
        /home/mayi/workspace/duduai/gobackend/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:416 +0xd6

goroutine 7 [syscall]:
os/signal.signal_recv(0x0)
        /usr/local/go/src/runtime/sigqueue.go:147 +0x9c
os/signal.loop()
        /usr/local/go/src/os/signal/signal_unix.go:23 +0x22
created by os/signal.Notify.func1
        /usr/local/go/src/os/signal/signal.go:127 +0x44

goroutine 9 [runnable]:
k8s.io/sample-controller/pkg/signals.SetupSignalHandler.func1(0xc0003eb200, 0xc00008ecc0)
        /home/mayi/workspace/github/sample-controller/pkg/signals/signal.go:35
created by k8s.io/sample-controller/pkg/signals.SetupSignalHandler
        /home/mayi/workspace/github/sample-controller/pkg/signals/signal.go:35 +0xd0

需要修改admin.conf权限

[vagrant@node1 sample-controller]$ sudo chmod a+r /etc/kubernetes/admin.conf   

运行controller

[vagrant@node1 sample-controller]$ ./sample-controller -kubeconfig /etc/kubernetes/admin.conf                                                                                                               
I0806 15:48:46.715501   15474 controller.go:115] Setting up event handlers
I0806 15:48:46.715598   15474 controller.go:156] Starting Foo controller
I0806 15:48:46.715622   15474 controller.go:159] Waiting for informer caches to sync
I0806 15:48:46.819997   15474 controller.go:164] Starting workers
I0806 15:48:46.820046   15474 controller.go:170] Started workers
I0806 15:50:54.870759   15474 controller.go:228] Successfully synced 'default/example-foo'
I0806 15:50:54.871685   15474 event.go:291] "Event occurred" object="default/example-foo" kind="Foo" apiVersion="samplecontroller.k8s.io/v1alpha1" type="Normal" reason="Synced" message="Foo synced successfully"
I0806 15:50:54.877213   15474 controller.go:228] Successfully synced 'default/example-foo'
I0806 15:50:54.877423   15474 event.go:291] "Event occurred" object="default/example-foo" kind="Foo" apiVersion="samplecontroller.k8s.io/v1alpha1" type="Normal" reason="Synced" message="Foo synced successfully"
I0806 15:50:54.885137   15474 controller.go:228] Successfully synced 'default/example-foo'
I0806 15:50:54.885176   15474 event.go:291] "Event occurred" object="default/example-foo" kind="Foo" apiVersion="samplecontroller.k8s.io/v1alpha1" type="Normal" reason="Synced" message="Foo synced successfully"
I0806 15:50:54.934593   15474 controller.go:228] Successfully synced 'default/example-foo'
I0806 15:50:54.934717   15474 event.go:291] "Event occurred" object="default/example-foo" kind="Foo" apiVersion="samplecontroller.k8s.io/v1alpha1" type="Normal" reason="Synced" message="Foo synced successfully"
I0806 15:51:16.782318   15474 controller.go:228] Successfully synced 'default/example-foo'
I0806 15:51:16.782922   15474 event.go:291] "Event occurred" object="default/example-foo" kind="Foo" apiVersion="samplecontroller.k8s.io/v1alpha1" type="Normal" reason="Synced" message="Foo synced successfully"
I0806 15:51:46.784112   15474 controller.go:228] Successfully synced 'default/example-foo'
I0806 15:51:46.784584   15474 event.go:291] "Event occurred" object="default/example-foo" kind="Foo" apiVersion="samplecontroller.k8s.io/v1alpha1" type="Normal" reason="Synced" message="Foo synced successfully"
I0806 15:52:16.782987   15474 controller.go:228] Successfully synced 'default/example-foo'
I0806 15:52:16.783071   15474 event.go:291] "Event occurred" object="default/example-foo" kind="Foo" apiVersion="samplecontroller.k8s.io/v1alpha1" type="Normal" reason="Synced" message="Foo synced successfully"

1.3 验证运行情况

[vagrant@node1 sample-controller]$ kubectl get pod
NAME                                             READY   STATUS              RESTARTS   AGE
echo-goodbye-run-xcf84-echo-zpt8p-pod-sftql      0/1     Completed           0          24d
echo-goodbye-run-xcf84-goodbye-ltgp2-pod-kwl4j   0/1     Completed           0          24d
echo-run-4kb2p-pod-xswn8                         0/1     Completed           0          57d
echo-run-76vs2-pod-n22jv                         0/1     Completed           0          24d
echo-run-hfs8h-pod-bgkvt                         0/1     Completed           0          24d
example-foo-757bd7c455-dvr7x                     0/1     ContainerCreating   0          30s
goodbye-run-vcgnw-pod-k4fsn                      0/1     Completed           0          24d


[vagrant@node1 sample-controller]$ kubectl get pod
NAME                                             READY   STATUS      RESTARTS   AGE
echo-goodbye-run-xcf84-echo-zpt8p-pod-sftql      0/1     Completed   0          24d
echo-goodbye-run-xcf84-goodbye-ltgp2-pod-kwl4j   0/1     Completed   0          24d
echo-run-4kb2p-pod-xswn8                         0/1     Completed   0          57d
echo-run-76vs2-pod-n22jv                         0/1     Completed   0          24d
echo-run-hfs8h-pod-bgkvt                         0/1     Completed   0          24d
example-foo-757bd7c455-dvr7x                     1/1     Running     0          3m23s
goodbye-run-vcgnw-pod-k4fsn                      0/1     Completed   0          24d


[vagrant@node1 sample-controller]$ kubectl get deployments.apps 
NAME                            READY   UP-TO-DATE   AVAILABLE   AGE
example-foo                     0/1     1            0           42s
jn9s-python-m8x5m-deployment    0/0     0            0           78d
jn9s-python2-c4nql-deployment   0/0     0            0           78d
jnocr-lwlcf-deployment          0/0     0            0           77d



[vagrant@node1 sample-controller]$ kubectl describe Foo example-foo
Name:         example-foo
Namespace:    default
Labels:       
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"samplecontroller.k8s.io/v1alpha1","kind":"Foo","metadata":{"annotations":{},"name":"example-foo","namespace":"default"},"sp...
API Version:  samplecontroller.k8s.io/v1alpha1
Kind:         Foo
Metadata:
  Creation Timestamp:  2020-08-06T07:50:54Z
  Generation:          2
  Resource Version:    12298681
  Self Link:           /apis/samplecontroller.k8s.io/v1alpha1/namespaces/default/foos/example-foo
  UID:                 e6899918-216a-4b1c-980c-2bf735276e28
Spec:
  Deployment Name:  example-foo
  Replicas:         1
Status:
  Available Replicas:  0
Events:
  Type    Reason  Age                  From               Message
  ----    ------  ----                 ----               -------
  Normal  Synced  2s (x10 over 2m54s)  sample-controller  Foo synced successfully




[vagrant@node1 sample-controller]$ kubectl get Foo
NAME          AGE
example-foo   6m40s


[vagrant@node1 sample-controller]$ kubectl logs example-foo-757bd7c455-dvr7x 
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up


你可能感兴趣的:(kubernetes samplecontroller 编译部署测试)