/
server.go
75 lines (72 loc) · 1.55 KB
/
server.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
package resources
import (
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
)
func HTTPServerDeployment(name, namespace string) *appsv1.Deployment {
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": name,
},
},
Replicas: pointer.Int32(1),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": name,
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: name,
Image: "quay.io/rhrazdil/alpine:v0.1",
Ports: []v1.ContainerPort{
{
ContainerPort: 80,
},
},
Command: []string{
"/bin/sh",
},
Args: []string{
"-c",
"while true; do echo -e \"HTTP/1.1 200 OK\\n\\nHello World!\" | nc -l -p 80 ; done",
},
},
},
},
},
},
}
}
func HTTPServerService(name, namespace string) *v1.Service {
return &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: v1.ServiceSpec{
Selector: map[string]string{
"app": name,
},
Ports: []v1.ServicePort{
{
Protocol: "TCP",
Port: 80,
TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: 80},
},
},
Type: v1.ServiceTypeLoadBalancer,
},
}
}