Skip to content

Commit 599d4e7

Browse files
kangarlouclintonk
authored andcommitted
Changed the Trident installer to support RBAC
The installer script creates service accounts, cluster roles, and cluster role bindings for Trident and Trident launcher The default namespace for Trident has changed from "default" to the working namespace The installer supports installing Trident in a different namespace (./install_trident.sh -n trident) Added a script for deleting most artificats of the installer Added a script for updating or rolling back containers in the Trident deployment
1 parent 934c3de commit 599d4e7

13 files changed

+479
-81
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ kubernetes-yaml/trident-deployment-local.yaml
1313
launcher/kubernetes-yaml/launcher-pod-local.yaml
1414
launcher/config/
1515
trident-installer.tar.gz
16-
trident-installer/launcher-pod.yaml
16+
trident-installer/*.yaml
1717
trident-installer/setup
1818
trident
1919

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ dist_tar:
201201
@mkdir -p trident-installer/setup
202202
@sed "s|__LAUNCHER_TAG__|${LAUNCHER_DIST_TAG}|g" ./launcher/kubernetes-yaml/launcher-pod.yaml.templ > trident-installer/launcher-pod.yaml
203203
@sed "s|__TRIDENT_IMAGE__|${TRIDENT_DIST_TAG}|g" kubernetes-yaml/trident-deployment.yaml.templ > trident-installer/setup/trident-deployment.yaml
204+
@cp kubernetes-yaml/trident-namespace.yaml trident-installer/
205+
@cp kubernetes-yaml/trident-serviceaccounts.yaml trident-installer/
206+
@cp kubernetes-yaml/trident-clusterrole* trident-installer/
204207
@tar -czf trident-installer-${TRIDENT_DIST_VERSION}.tar.gz trident-installer
205208

206209
dist_tag:

README.md

+77-29
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,24 @@ are not available, see the subsequent sections.
120120
7. Copy the backend configuration file from step 6 the `setup/` directory
121121
and name it `backend.json`.
122122

123-
8. Run the Trident installation script. If using Kubernetes, run:
123+
8. Run the Trident installation script:
124124

125125
```bash
126-
./install_trident.sh
126+
./install_trident.sh -n trident
127127
```
128-
129-
If using OpenShift, run:
130-
131-
```bash
132-
./install_trident.sh --namespace <namespace> --serviceaccount trident
133-
```
134-
135-
where the `--namespace` argument is optional.
128+
where the `-n` argument is optional and specifies the namespace for the
129+
Trident deployment. If not specified, namespace defaults to the current
130+
namespace; however, it is highly recommended to run Trident in its own
131+
namespace so that it is isoloated from other applications in the cluster.
136132

137133
The install script first configures the Trident deployment and Trident
138134
launcher pod definitions, found in `setup/trident-deployment.yaml` and
139135
`launcher-pod.yaml`, to use the namespace and service account specified
140-
(defaulting to `default` for both if unspecified, as in the Kubernetes
141-
command above). It then starts the Trident launcher pod, which provisions
142-
a PVC and PV on which Trident will store its data, using the provided
143-
backend. The launcher then starts a deployment for Trident itself, using
144-
the defintion in `setup/`.
136+
(defaulting to the current namespace for both if unspecified, as in the
137+
Kubernetes command above). It then starts the Trident launcher pod,
138+
which provisions a PVC and PV on which Trident will store its data, using
139+
the provided backend. The launcher then starts a deployment for Trident
140+
itself, using the defintion in `setup/`.
145141

146142
When the installer completes, `kubectl get deployment trident` should show
147143
a deployment named `trident` with a single live replica. Running `kubectl
@@ -304,10 +300,22 @@ parameters:
304300
* `-deployment_file`: The path to a Trident deployment definition, as
305301
described in [Deploying As a Pod](#deploying-as-a-pod). Defaults to
306302
`/etc/config/trident-deployment.yaml`.
307-
* `-apiserver`: The IP address and insecure port for the Kubernetes API
303+
* `-apiserver`: The IP address and insecure port for the Kubernetes API
308304
server. Optional; if specified, the launcher uses this to communicate with
309305
the API server. If omitted, the launcher will assume it is being launched as
310306
a Kubernetes pod and connect using the service account for that pod.
307+
* `-volume_name`: The name of the volume provisioned by launcher on the storage
308+
backend. If omitted, it defaults to "trident".
309+
* `-volume_size`: The size of the volume provisioned by launcher in GB. If
310+
omitted, it defaults to 1GB.
311+
* `pvc_name`: The name of the PVC created by launcher. If omitted, it defaults
312+
to "trident".
313+
* `pv_name`: The name of the PV created by launcher. If omitted, it defaults
314+
to "trident".
315+
* `-trident_timeout`: The number of seconds to wait before the launcher times
316+
out on a Trident connection. If omitted, it defaults to 10 seconds.
317+
* `-k8s_timeout`: The number of seconds to wait before timing out on Kubernetes
318+
operations. If omitted, it defaults to 60 seconds.
311319
* `-debug`: Optional; enables debugging output.
312320

313321
As with Trident itself, the launcher can be deployed as a pod using the
@@ -341,19 +349,59 @@ Trident launcher and CLI, and several sample input files for Trident. The insta
341349
script requires a backend configuration named `backend.json` to be added to the
342350
`setup/` directory. Once this has been done, it will create the ConfigMap
343351
described above using the files in `setup/` and then launch the Trident
344-
deployment. It takes two optional parameters:
345-
346-
* `-n <namespace>`/`--namespace <namespace>`: Namespace in which to deploy
347-
Trident and the Trident launcher. Defaults to `default`.
348-
* `-s <service-account>`/`--serviceaccount <service-account>`: Service account
349-
to use for Trident and the Trident launcher. Defaults to `default`.
350-
351-
The script will change the deployment definition files (`launcher-pod.yaml` and
352-
`setup/trident-deployment.yaml`) provided based on these parameters. These
353-
defintions can also be changed manually as needed. Note that the script must
354-
be run with `kubectl` using a context with the namespace used in `--namespace`;
355-
otherwise, the ConfigMap will be created in the wrong namespace and the
356-
launcher will not run.
352+
deployment. This script can be run from any directory and from any namespace.
353+
```bash
354+
$ ./install_trident.sh -h
355+
356+
Usage:
357+
-n <namespace> Specifies the namespace for the Trident deployment; defaults to the current namespace.
358+
-h Prints this usage guide.
359+
360+
Example:
361+
./install_trident.sh -n trident Installs the Trident deployment in namespace "trident".
362+
```
363+
364+
It is highly recommended to run Trident in its own namespace
365+
(`./install_trident.sh -n trident`) so that it is isolated from other
366+
applications in the Kubernetes cluster. This script also creates service
367+
accounts, cluster roles, and cluster role bindings for both Trident and Trident
368+
launcher.
369+
370+
#### Delete Script
371+
372+
The delete script deletes most artifacts of the install script. This script can
373+
be run from any directory and from any namespace.
374+
```bash
375+
$ ./delete_trident.sh -h
376+
377+
Usage:
378+
-n <namespace> Specifies the namespace for the Trident deployment; defaults to the current namespace.
379+
-h Prints this usage guide.
380+
381+
Example:
382+
./delete_trident.sh -n trident Deletes artifacts of Trident from namespace "trident".
383+
```
384+
385+
This script does not delete the namespace, the PVC, and the PV created by the
386+
install script.
387+
388+
#### Update Script
389+
390+
The update script can be used to update or rollback container images in the
391+
Trident deployment.
392+
```bash
393+
$ ./update_trident.sh -h
394+
395+
Usage:
396+
-n <namespace> Specifies the namespace for the Trident deployment; defaults to the current namespace.
397+
-t <trident_image> Specifies the new image for the "trident-main" container in the Trident deployment.
398+
-e <etcd_image> Specifies the new image for the "etcd" container in the Trident deployment.
399+
-d <deployment> Specifies the name of the deployment; defaults to "trident".
400+
-h Prints this usage guide.
401+
402+
Example:
403+
./update_trident.sh -n trident -t netapp/trident:17.04.1 Updates the Trident deployment in namespace "trident" to use image "netapp/trident:17.04.1".
404+
```
357405
358406
### Deploying As a Pod
359407
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
kind: ClusterRoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1alpha1
3+
metadata:
4+
name: trident
5+
subjects:
6+
- kind: ServiceAccount
7+
name: trident
8+
namespace: trident
9+
roleRef:
10+
kind: ClusterRole
11+
name: trident
12+
apiGroup: rbac.authorization.k8s.io
13+
---
14+
kind: ClusterRoleBinding
15+
apiVersion: rbac.authorization.k8s.io/v1alpha1
16+
metadata:
17+
name: trident-launcher
18+
subjects:
19+
- kind: ServiceAccount
20+
name: trident-launcher
21+
namespace: trident
22+
roleRef:
23+
kind: ClusterRole
24+
name: trident-launcher
25+
apiGroup: rbac.authorization.k8s.io
26+
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
kind: ClusterRole
2+
apiVersion: rbac.authorization.k8s.io/v1alpha1
3+
metadata:
4+
name: trident
5+
rules:
6+
- apiGroups: [""]
7+
resources: ["persistentvolumes"]
8+
verbs: ["get", "list", "watch", "create", "delete"]
9+
- apiGroups: [""]
10+
resources: ["persistentvolumeclaims"]
11+
verbs: ["get", "list", "watch", "update"]
12+
- apiGroups: ["storage.k8s.io"]
13+
resources: ["storageclasses"]
14+
verbs: ["get", "list", "watch"]
15+
- apiGroups: [""]
16+
resources: ["events"]
17+
verbs: ["watch", "create", "update", "patch"]
18+
---
19+
kind: ClusterRole
20+
apiVersion: rbac.authorization.k8s.io/v1alpha1
21+
metadata:
22+
name: trident-launcher
23+
rules:
24+
- apiGroups: [""]
25+
resources: ["persistentvolumes"]
26+
verbs: ["get", "list", "watch", "create", "delete"]
27+
- apiGroups: [""]
28+
resources: ["persistentvolumeclaims"]
29+
verbs: ["get", "list", "watch", "create", "delete"]
30+
- apiGroups: [""]
31+
resources: ["pods", "pods/log"]
32+
verbs: ["get", "list", "watch", "create", "delete"]
33+
- apiGroups: ["extensions", "apps"]
34+
resources: ["deployments"]
35+
verbs: ["get", "list", "watch", "create", "delete"]

kubernetes-yaml/trident-deployment.yaml.templ

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ apiVersion: extensions/v1beta1
22
kind: Deployment
33
metadata:
44
name: trident
5-
namespace: default
65
labels:
76
app: trident.netapp.io
8-
kubernetes.io/cluster-service: "true"
97
spec:
108
replicas: 1
119
template:
1210
metadata:
1311
labels:
1412
app: trident.netapp.io
1513
spec:
16-
serviceAccount: default
14+
serviceAccount: trident
1715
containers:
1816
- name: trident-main
1917
image: __TRIDENT_IMAGE__
@@ -25,6 +23,7 @@ spec:
2523
- "-k8s_pod"
2624
#- "-k8s_api_server"
2725
#- "__KUBERNETES_SERVER__:__KUBERNETES_PORT__"
26+
#- "-debug"
2827
- name: etcd
2928
image: quay.io/coreos/etcd:v3.1.3
3029
command:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: trident
5+
---
6+
apiVersion: v1
7+
kind: ServiceAccount
8+
metadata:
9+
name: trident-launcher
10+

launcher/kubernetes-yaml/launcher-pod.yaml.templ

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ apiVersion: v1
22
kind: Pod
33
metadata:
44
name: trident-launcher
5-
namespace: default
65
spec:
7-
serviceAccount: default
6+
serviceAccount: trident-launcher
87
containers:
98
- name: launcher
109
image: __LAUNCHER_TAG__

launcher/launcher.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
tridentEphemeralPodName = "trident-ephemeral"
3535
tridentDefaultPort = 8000
3636
tridentStorageClassName = "trident-basic"
37+
tridentNamespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
3738
//based on the number of seconds Trident waits on etcd to bootstrap
3839
bootstrappingTimeout int64 = 11
3940
)
@@ -46,7 +47,7 @@ var (
4647
"/etc/config/trident-deployment.yaml", "Deployment definition file for Trident")
4748
debug = flag.Bool("debug", false, "Enable debug output.")
4849
k8sTimeout = flag.Int64("k8s_timeout", 60, "The number of seconds to wait before timing out on Kubernetes operations.")
49-
tridentVolumeSize = flag.Int("volume_size", 1, "The size of the volume used by etcd in GB.")
50+
tridentVolumeSize = flag.Int("volume_size", 1, "The size of the volume provisioned by launcher in GB.")
5051
tridentVolumeName = flag.String("volume_name", "trident", "The name of the volume used by etcd.")
5152
tridentPVCName = flag.String("pvc_name", "trident", "The name of the PVC used by Trident.")
5253
tridentPVName = flag.String("pv_name", "trident", "The name of the PV used by Trident.")
@@ -694,8 +695,14 @@ func (launcher *Launcher) Run() (errors []error) {
694695
return
695696
}
696697
if pv, err = createPV(launcher.kubeClient, *tridentPVName, volConfig, pvc); err != nil {
697-
launcherErr = fmt.Errorf("Launcher failed in creating PV %s: %s",
698-
*tridentPVName, err)
698+
launcherErr = fmt.Errorf("Launcher failed in creating PV %s: %s. "+
699+
"Either use -pv_name in launcher-pod.yaml to create a volume "+
700+
"and a PV with a different name, or delete PV %s so that "+
701+
"launcher can create a new PV with the same name. "+
702+
"(The new PV will reuse the volume represented by the old "+
703+
"PV unless the volume is manually deleted from the storage "+
704+
"backend.)",
705+
*tridentPVName, err, *tridentPVName)
699706
return
700707
}
701708
pvCreated = true
@@ -820,7 +827,14 @@ func main() {
820827
for _, container := range tridentDeployment.Spec.Template.Spec.Containers {
821828
if container.Name == tridentContainerName {
822829
tridentImage = container.Image
823-
tridentNamespace = tridentDeployment.Namespace
830+
bytes, err := ioutil.ReadFile(tridentNamespaceFile)
831+
if err != nil {
832+
log.WithFields(log.Fields{
833+
"error": err,
834+
"namespaceFile": tridentNamespaceFile,
835+
}).Fatal("Launcher failed to obtain the namespace for the launcher pod!")
836+
}
837+
tridentNamespace = string(bytes)
824838
break
825839
}
826840
}

launcher/launcher_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestValidKubeVersion(t *testing.T) {
2929
}
3030
}
3131

32-
func TestInvalidKubeVersion1(t *testing.T) {
32+
func TestInvalidKubeVersion(t *testing.T) {
3333
k8sVersion := &version.Info{
3434
Major: "1",
3535
Minor: "3",

0 commit comments

Comments
 (0)