forked from asafsofer-sl/AKS_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAKS_tools.pl
215 lines (168 loc) · 7.5 KB
/
AKS_tools.pl
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
#!/usr/bin/env perl
#######################################################################################################################
#Script : AKS_tools
#Usage : ./AKS_tools
#Purpose : Various Config Validations,search,locate files etc..
#Prerequisites : Files
# 1. AKS_tools ( script )
# Contact : Asaf Sofer
#######################################################################################################################
#Take date
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
our $Date = sprintf("%.2d-%.2d-%.2d",$mon+1,$mday,$year+1900);
our $Time = sprintf("%.2d:%.2d:%.2d",$hour,$min,$sec);
print "\nSelect Action :\n \t 1. uptime-sla \n\t 2. reconcile the cluster \n\t 3. restart kube-dns pods \n\t 4. resart tunnel pods \n\t 5. resart kube-proxy pods \n\t 6. upgrade cluster \n\t 7. get pods logs \n\t 8. get kube-system pods \n\t 9. describe node \n\t 10. get nodes list \n\t 11. Show the details for a managed Kubernetes cluster \n\t 12. scale number of nodes up/down \n\t 13. create new nodepool \n\t 14. get nodepool names only \n\t 15. get nodepool list \n\n\t 0. exit\n";
print "\n--Your Choice :";
$act= <STDIN>;
chomp($act);
if($act eq 1)
{
print "\n Uptime SLA is a tier to enable a financially backed, higher SLA for an AKS cluster. Clusters with Uptime SLA, also regarded as Paid tier in AKS REST APIs, come with greater amount of control plane resources and automatically scale to meet the load of your cluster. Uptime SLA guarantees 99.95% availability of the Kubernetes API server endpoint for clusters that use Availability Zones and 99.9% of availability for clusters that don't use Availability Zones. AKS uses master node replicas across update and fault domains to ensure SLA requirements are met. \n";
print "\nplease provide the subscriptions ID: \n";
$sub= <STDIN>;
chomp($sub);
print "\nenable the uptime-sla \n";
print "\nplease provide the resource group: \n";
$rg= <STDIN>;
chomp($rg);
print "\nplease provide the clsuter name: \n";
$clus= <STDIN>;
chomp($clus);
exec("az aks update --resource-group $rg --name $clus --uptime-sla");
print "\n===========================reconsile the cluster below ============================\n";
print "\n az resource update --ids /subscriptions/$sub/resourceGroups/$rg/providers/Microsoft.ContainerService/managedClusters/$clus \n";
}
if($act eq 2)
{
print "\n We reconcile the control plane & worker node pole with below command, the command below just doing PUT command with empty string and no impact on Production work \n";
print "\nplease provide the subscriptions ID: \n";
$sub= <STDIN>;
chomp($sub);
print "\nplease provide the resource group: \n";
$rg= <STDIN>;
chomp($rg);
print "\nplease provide the clsuter name: \n";
$clus= <STDIN>;
chomp($clus);
print "\n===========================reconsile the cluster below ============================\n";
print "\n az resource update --ids /subscriptions/$sub/resourceGroups/$rg/providers/Microsoft.ContainerService/managedClusters/$clus \n";
print "\n\t 1. confirm to continue \n\t 0. exit\n";
print "\n--Your Choice :"; $in= <STDIN>;chomp($in);
if($in eq 1) {
exec("az resource update --ids /subscriptions/$sub/resourceGroups/$rg/providers/Microsoft.ContainerService/managedClusters/$clus");
}
}
if($act eq 3) {
exec("kubectl delete po -l k8s-app=kube-dns -n kube-system");
}
if($act eq 4) {
exec("kubectl delete po -l component=tunnel -n kube-system");
}
if($act eq 5) {
exec("kubectl delete po -l component=kube-proxy -n kube-system");
}
if($act eq 6) {
print "\nplease provide the resource group: \n";
$myResourceGroup=<STDIN>;
chomp($myResourceGroup);
print "\nplease provide the cluster name: \n";
$myAKSCluster=<STDIN>;
chomp($myAKSCluster);
print "\nplease provide the target version need to upgrade to: \n";
$KUBERNETES_VERSION=<STDIN>;
chomp($KUBERNETES_VERSION);
print "\n\t 1. confirm to continue \n\t 0. exit\n";
print "\n--Your Choice :"; $in= <STDIN>;chomp($in);
if($in eq 1) {
exec("az aks upgrade --resource-group $myResourceGroup --name $myAKSCluster --kubernetes-version $KUBERNETES_VERSION");
}
}
if ($act eq 7) {
print "\nplease provide the pod name : \n";
$pod= <STDIN>;
chomp($pod);
print "\nplease provide the pod name space : \n";
$ns= <STDIN>;
chomp($ns);
exec("kubectl logs $pod -n $ns");
}
if($act eq 8) {
print "\n------------ kube system : ----------------------------------------------------\n";
exec("kubectl get pods -n kube-system");
}
if($act eq 9) {
print "\nplease provide node name : \n";
$node=<STDIN>;
chomp($node);
exec("kubectl describe node $node");
}
if($act eq 10) {
print "\n------------ Node List : ----------------------------------------------------\n";
exec("kubectl get nodes -o wide");
}
if($act eq 11) {
print "\nplease provide the resource group: \n";
$myResourceGroup=<STDIN>;
chomp($myResourceGroup);
print "\nplease provide the cluster name: \n";
$myAKSCluster=<STDIN>;
chomp($myAKSCluster);
print "\n\t 1. show output in CLI \n\t 2. extract output to Results.txt\n";
print "\n--Your Choice :"; $in= <STDIN>;chomp($in);
if($in eq 1) {
exec("az aks show --resource-group $myResourceGroup --name $myAKSCluster")
}
else{
exec("az aks show --resource-group $myResourceGroup --name $myAKSCluster >> Results.txt")
}
}
if($act eq 12) {
print "\nplease provide the resource group: \n";
$myResourceGroup=<STDIN>;
chomp($myResourceGroup);
print "\nplease provide the cluster name: \n";
$myAKSCluster=<STDIN>;
chomp($myAKSCluster);
print "\nplease provide number of nodes needed: \n";
$index=<STDIN>;
chomp($index);
print "\nplease provide your node pool name: \n";
$agentpool=<STDIN>;
chomp($agentpool);
exec("az aks scale --resource-group $myResourceGroup --name $myAKSCluster --node-count $index --nodepool-name $agentpool")
}
if($act eq 13) {
print "\n---please be aware that use nodepool will be created , and it is supported only with standard LB---\n";
print "\nplease provide the resource group: \n";
$myResourceGroup=<STDIN>;
chomp($myResourceGroup);
print "\nplease provide the cluster name: \n";
$myAKSCluster=<STDIN>;
chomp($myAKSCluster);
print "\nplease provide number of nodes needed: \n";
$index=<STDIN>;
chomp($index);
print "\nplease provide node new pool name: \n";
$agentpool=<STDIN>;
chomp($agentpool);
exec("az aks nodepool add --resource-group $myResourceGroup --cluster-name $myAKSCluster --name $agentpool --node-count $index")
}
if($act eq 14) {
print "\nplease provide the resource group: \n";
$myResourceGroup=<STDIN>;
chomp($myResourceGroup);
print "\nplease provide the cluster name: \n";
$myAKSCluster=<STDIN>;
chomp($myAKSCluster);
exec("az aks nodepool list --cluster-name $myAKSCluster --resource-group $myResourceGroup|grep name")
}
if($act eq 15) {
print "\n---output will be save to file name: nodepool_list.txt---\n";
print "\nplease provide the resource group: \n";
$myResourceGroup=<STDIN>;
chomp($myResourceGroup);
print "\nplease provide the cluster name: \n";
$myAKSCluster=<STDIN>;
chomp($myAKSCluster);
exec("az aks nodepool list --cluster-name $myAKSCluster --resource-group $myResourceGroup >> nodepool_list.txt")
}