-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout-k8s.go
124 lines (106 loc) · 2.72 KB
/
out-k8s.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"flag"
"fmt"
// "time"
// "common/jsonx"
"k8s.io/client-go/1.4/kubernetes"
"k8s.io/client-go/1.4/pkg/api"
// "k8s.io/client-go/1.4/pkg/api/resource"
// "k8s.io/client-go/1.4/pkg/api/unversioned"
// "k8s.io/client-go/1.4/pkg/api/v1"
"k8s.io/client-go/1.4/tools/clientcmd"
)
var (
kubeconfig = flag.String("kubeconfig", "./config", "absolute path to the kubeconfig file")
)
func main() {
flag.Parse()
// uses the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("183.131.19.231:8080", *kubeconfig)
if err != nil {
panic(err.Error())
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
/*//创建replicationController
rcTypeMeta := unversioned.TypeMeta{Kind: "ReplicationController", APIVersion: "v1"}
rcObjectMeta := v1.ObjectMeta{
Name: "redis",
Labels: map[string]string{
"name": "redis",
},
}
instanceCnt := int32(2)
rcSpec := v1.ReplicationControllerSpec{
Replicas: &instanceCnt,
Selector: map[string]string{
"name": "redis",
},
Template: &v1.PodTemplateSpec{
v1.ObjectMeta{
Labels: map[string]string{
"name": "redis",
},
},
v1.PodSpec{
Containers: []v1.Container{
v1.Container{
Name: "redis",
Image: "redis",
Ports: []v1.ContainerPort{
v1.ContainerPort{
ContainerPort: 6379,
Protocol: v1.ProtocolTCP,
},
},
Resources: v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("100m"),
v1.ResourceMemory: resource.MustParse("100Mi"),
},
},
},
},
},
},
}
rc := new(v1.ReplicationController)
rc.TypeMeta = rcTypeMeta
rc.ObjectMeta = rcObjectMeta
rc.Spec = rcSpec
//创建
result, err := clientset.Core().ReplicationControllers("default").Create(rc)
if err != nil {
fmt.Printf("deploy application failed ,the reason is %s", err.Error())
fmt.Println()
}
str, _ := jsonx.ToJson(result)
fmt.Printf("the result is %v", str)
fmt.Println()*/
// err = clientset.Core().ReplicationControllers("default").Delete("redis", &api.DeleteOptions{
// TypeMeta: unversioned.TypeMeta{
// Kind: "ReplicationController",
// APIVersion: "v1",
// },
// OrphanDependents: new(bool),
// })
// if err != nil {
// fmt.Printf("err is %v", err.Error())
// }
// for {
pods, err := clientset.Core().Pods("default").List(api.ListOptions{})
if err != nil {
panic(err.Error())
}
for i := 0; i < len(pods.Items); i++ {
}
fmt.Printf("There are %#v pods in the cluster\n", pods)
// str, _ := jsonx.ToJson(pods.Items)
// fmt.Printf("pods in the cluster is %v \n", str)
// time.Sleep(10 * time.Second)
// }
}