-
Notifications
You must be signed in to change notification settings - Fork 822
/
examples.go
215 lines (194 loc) · 7.81 KB
/
examples.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
Copyright 2021 The Karmada Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils
import (
"fmt"
"k8s.io/klog/v2"
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/options"
)
const (
// https://github.com/karmada-io/karmada/blob/master/artifacts/agent
karmadaAgent = `---
apiVersion: v1
kind: Namespace
metadata:
name: karmada-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: karmada-agent
rules:
- apiGroups: ['*']
resources: ['*']
verbs: ['*']
- nonResourceURLs: ['*']
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: karmada-agent
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: karmada-agent
subjects:
- kind: ServiceAccount
name: karmada-agent-sa
namespace: karmada-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: karmada-agent-sa
namespace: karmada-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: karmada-agent
namespace: karmada-system
labels:
app: karmada-agent
spec:
replicas: 1
selector:
matchLabels:
app: karmada-agent
template:
metadata:
labels:
app: karmada-agent
spec:
serviceAccountName: karmada-agent-sa
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
containers:
- name: karmada-agent
image: docker.io/karmada/karmada-agent:latest
command:
- /bin/karmada-agent
- --karmada-kubeconfig=/etc/kubeconfig/karmada-kubeconfig
- --karmada-context=%s
- --cluster-name={member_cluster_name}
- --cluster-api-endpoint={member_cluster_api_endpoint}
- --cluster-status-update-frequency=10s
- --bind-address=0.0.0.0
- --secure-port=10357
- --v=4
livenessProbe:
httpGet:
path: /healthz
port: 10357
scheme: HTTP
failureThreshold: 3
initialDelaySeconds: 15
periodSeconds: 15
timeoutSeconds: 5
volumeMounts:
- name: kubeconfig
mountPath: /etc/kubeconfig
volumes:
- name: kubeconfig
secret:
secretName: karmada-kubeconfig`
estimator = `apiVersion: apps/v1
kind: Deployment
metadata:
name: karmada-scheduler-estimator-{{member_cluster_name}}
namespace: karmada-system
labels:
cluster: {{member_cluster_name}}
spec:
replicas: 1
selector:
matchLabels:
app: karmada-scheduler-estimator-{{member_cluster_name}}
template:
metadata:
labels:
app: karmada-scheduler-estimator-{{member_cluster_name}}
spec:
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
containers:
- name: karmada-scheduler-estimator
image: docker.io/karmada/karmada-scheduler-estimator:latest
imagePullPolicy: IfNotPresent
command:
- /bin/karmada-scheduler-estimator
- --kubeconfig=/etc/{{member_cluster_name}}-kubeconfig
- --cluster-name={{member_cluster_name}}
volumeMounts:
- name: member-kubeconfig
subPath: {{member_cluster_name}}-kubeconfig
mountPath: /etc/{{member_cluster_name}}-kubeconfig
volumes:
- name: member-kubeconfig
secret:
secretName: {{member_cluster_name}}-kubeconfig
---
apiVersion: v1
kind: Service
metadata:
name: karmada-scheduler-estimator-{{member_cluster_name}}
namespace: karmada-system
labels:
cluster: {{member_cluster_name}}
spec:
selector:
app: karmada-scheduler-estimator-{{member_cluster_name}}
ports:
- protocol: TCP
port: 10352
targetPort: 10352`
)
// GenExamples Generate sample files
func GenExamples(path, parentCommand, printRegisterCommand string) {
karmadaAgentStr := fmt.Sprintf(karmadaAgent, options.ClusterName)
if err := BytesToFile(path, "karmada-agent.yaml", []byte(karmadaAgentStr)); err != nil {
klog.Warning(err)
}
// https://github.com/karmada-io/karmada/blob/master/artifacts/deploy/karmada-scheduler-estimator.yaml
if err := BytesToFile(path, "karmada-scheduler-estimator.yaml", []byte(estimator)); err != nil {
klog.Warning(err)
}
fmt.Printf(`
------------------------------------------------------------------------------------------------------
█████ ████ █████████ ███████████ ██████ ██████ █████████ ██████████ █████████
░░███ ███░ ███░░░░░███ ░░███░░░░░███ ░░██████ ██████ ███░░░░░███ ░░███░░░░███ ███░░░░░███
░███ ███ ░███ ░███ ░███ ░███ ░███░█████░███ ░███ ░███ ░███ ░░███ ░███ ░███
░███████ ░███████████ ░██████████ ░███░░███ ░███ ░███████████ ░███ ░███ ░███████████
░███░░███ ░███░░░░░███ ░███░░░░░███ ░███ ░░░ ░███ ░███░░░░░███ ░███ ░███ ░███░░░░░███
░███ ░░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ███ ░███ ░███
█████ ░░████ █████ █████ █████ █████ █████ █████ █████ █████ ██████████ █████ █████
░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░
------------------------------------------------------------------------------------------------------
Karmada is installed successfully.
Register Kubernetes cluster to Karmada control plane.
Register cluster with 'Push' mode
Step 1: Use "%[2]s join" command to register the cluster to Karmada control plane. --cluster-kubeconfig is kubeconfig of the member cluster.
(In karmada)~# MEMBER_CLUSTER_NAME=$(cat ~/.kube/config | grep current-context | sed 's/: /\n/g'| sed '1d')
(In karmada)~# %[2]s --kubeconfig %[1]s/karmada-apiserver.config join ${MEMBER_CLUSTER_NAME} --cluster-kubeconfig=$HOME/.kube/config
Step 2: Show members of karmada
(In karmada)~# kubectl --kubeconfig %[1]s/karmada-apiserver.config get clusters
Register cluster with 'Pull' mode
Step 1: Use "%[2]s register" command to register the cluster to Karmada control plane. "--cluster-name" is set to cluster of current-context by default.
(In member cluster)~# %[2]s%[3]s
Step 2: Show members of karmada
(In karmada)~# kubectl --kubeconfig %[1]s/karmada-apiserver.config get clusters
`, path, parentCommand, printRegisterCommand)
}