Skip to content

Commit 1337622

Browse files
committed
Fix account.yaml
1 parent 1922763 commit 1337622

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ For numerical checks, the number is returned on success and zero or a negative n
122122

123123
## ServiceAccount and token
124124

125-
All the needed objects (ServiceAccount, ClusterRole, RoleBinding) can be created with this command:
125+
All the needed objects (ServiceAccount, Secret, ClusterRole, RoleBinding) can be created by Terraform with terraform.tf file or with this command:
126126

127127
kubectl apply -f https://raw.githubusercontent.com/agapoff/check_kubernetes/master/account.yaml
128128

129129
For mode pvc or tls you need to enable the permissions in the yaml first. Those two can have security implications and are thus disabled by default.
130130

131131
Then in order to get the token just issue this command:
132132

133-
kubectl -n monitoring get secret "$(kubectl -n monitoring get serviceaccount monitoring -o 'jsonpath={.secrets[0].name}')" -o "jsonpath={.data.token}" | openssl enc -d -base64 -A
133+
kubectl -n monitoring get secret monitoring -o "jsonpath={.data.token}" | openssl enc -d -base64 -A
134134

135135
## Example configuration for Icinga
136136

account.tf

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
resource "kubernetes_namespace_v1" "monitoring" {
2+
metadata {
3+
annotations = {
4+
name = "monitoring"
5+
}
6+
7+
name = "monitoring"
8+
}
9+
}
10+
11+
resource "kubernetes_service_account_v1" "monitoring" {
12+
metadata {
13+
name = "monitoring"
14+
namespace = kubernetes_namespace_v1.monitoring.metadata.0.name
15+
}
16+
17+
secret {
18+
name = "monitoring"
19+
}
20+
}
21+
22+
resource "kubernetes_secret_v1" "monitoring" {
23+
depends_on = [
24+
kubernetes_service_account_v1.monitoring
25+
]
26+
27+
metadata {
28+
name = "monitoring"
29+
namespace = kubernetes_namespace_v1.monitoring.metadata.0.name
30+
31+
annotations = {
32+
"kubernetes.io/service-account.name" = "monitoring"
33+
"kubernetes.io/service-account.namespace" = "monitoring"
34+
}
35+
}
36+
37+
type = "kubernetes.io/service-account-token"
38+
}
39+
40+
resource "kubernetes_cluster_role_v1" "monitoring" {
41+
metadata {
42+
name = "monitoring"
43+
}
44+
45+
rule {
46+
api_groups = [""]
47+
resources = ["pods", "nodes", "secrets", "persistentvolumes"]
48+
verbs = ["get", "list"]
49+
}
50+
51+
rule {
52+
api_groups = ["extensions", "apps"]
53+
resources = ["deployments", "replicasets", "daemonsets", "statefulsets"]
54+
verbs = ["get", "list"]
55+
}
56+
57+
rule {
58+
api_groups = ["batch"]
59+
resources = ["jobs"]
60+
verbs = ["get", "list"]
61+
}
62+
}
63+
64+
resource "kubernetes_cluster_role_binding_v1" "monitoring" {
65+
metadata {
66+
name = "monitoring"
67+
}
68+
role_ref {
69+
api_group = "rbac.authorization.k8s.io"
70+
kind = "ClusterRole"
71+
name = "monitoring"
72+
}
73+
subject {
74+
kind = "ServiceAccount"
75+
name = "monitoring"
76+
namespace = kubernetes_namespace_v1.monitoring.metadata.0.name
77+
}
78+
}

account.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ metadata:
1111
name: monitoring
1212
namespace: monitoring
1313

14+
---
15+
apiVersion: v1
16+
kind: Secret
17+
metadata:
18+
name: monitoring
19+
namespace: monitoring
20+
annotations:
21+
kubernetes.io/service-account.name: "monitoring"
22+
type: kubernetes.io/service-account-token
23+
1424
---
1525
kind: ClusterRole
1626
apiVersion: rbac.authorization.k8s.io/v1

0 commit comments

Comments
 (0)