-
Notifications
You must be signed in to change notification settings - Fork 0
/
daemonset.go
95 lines (91 loc) · 2.28 KB
/
daemonset.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
package api
import (
"context"
"fmt"
appsv1 "k8s.io/api/apps/v1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func CreateDaemonSet() {
fmt.Println("Creating DaemonSet ...")
clientset := CreateClientSet()
daemonSetClient := clientset.AppsV1().DaemonSets(apiv1.NamespaceDefault)
daemonSet := &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test-daemonset",
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "elasticsearch",
},
},
Template: apiv1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "elasticsearch",
},
},
Spec: apiv1.PodSpec{
Tolerations: []apiv1.Toleration{
{
Key: "node-role.kubernetes.io/master",
Effect: "NoSchedule",
},
},
Containers: []apiv1.Container{
{
Name: "elasticsearch",
Image: "elasticsearch:7.10.1",
Resources: apiv1.ResourceRequirements{
Limits: apiv1.ResourceList{
apiv1.ResourceMemory: resource.MustParse("200Mi"),
},
Requests: apiv1.ResourceList{
apiv1.ResourceMemory: resource.MustParse("200Mi"),
apiv1.ResourceCPU: resource.MustParse("100m"),
},
},
VolumeMounts: []apiv1.VolumeMount{
{
Name: "varlog",
MountPath: "/var/log",
},
{
Name: "varlibdockercontainers",
MountPath: "/var/lib/docker/containers",
},
},
},
},
TerminationGracePeriodSeconds: int64Ptr(30),
Volumes: []apiv1.Volume{
{
Name: "varlog",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/var/log",
},
},
},
{
Name: "varlibdockercontainers",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/var/lib/docker/containers",
},
},
},
},
},
},
},
}
result, err := daemonSetClient.Create(context.TODO(), daemonSet, metav1.CreateOptions{})
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Created Daemonset %q\n", result.GetObjectMeta().GetName())
}