-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathKodeKloud Cheatsheet Devops Task Commands.txt
More file actions
7041 lines (5561 loc) · 288 KB
/
KodeKloud Cheatsheet Devops Task Commands.txt
File metadata and controls
7041 lines (5561 loc) · 288 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Task 1 - Task 36 : Kodekloud Cheatsheat SysAdmin Task Commands.txt
--------------------------------------------------------------------------------------------------------------------------------------------
Task 37 : 14/Feb/2022
Create Replicaset in Kubernetes Cluster
The Nautilus DevOps team is going to deploy some applications on kubernetes cluster as they are planning to migrate some of their existing applications there. Recently one of the team members has been assigned a task to write a template as per details mentioned below:
Create a ReplicaSet using httpd image with latest tag only and remember to mention tag i.e httpd:latest and name it as httpd-replicaset.
Labels app should be httpd_app, labels type should be front-end. The container should be named as httpd-container; also make sure replicas counts are 4.
Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
1.
thor@jump_host ~$ kubectl get deploy
No resources found in default namespace.
2.
thor@jump_host ~$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 57m
3.
thor@jump_host ~$ vi /tmp/httpd.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: httpd-replicaset
labels:
app: httpd_app
type: front-end
spec:
replicas: 4
selector:
matchLabels:
app: httpd_app
template:
metadata:
labels:
app: httpd_app
type: front-end
spec:
containers:
- name: httpd-container
image: httpd:latest
4.
thor@jump_host ~$ cat /tmp/httpd.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: httpd-replicaset
labels:
app: httpd_app
type: front-end
spec:
replicas: 4
selector:
matchLabels:
app: httpd_app
template:
metadata:
labels:
app: httpd_app
type: front-end
spec:
containers:
- name: httpd-container
image: httpd:latest
5.
thor@jump_host ~$ kubectl create -f /tmp/httpd.yaml
replicaset.apps/httpd-replicaset created
6.
thor@jump_host ~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
httpd-replicaset-9ddvb 0/1 ContainerCreating 0 13s
httpd-replicaset-ndtzd 0/1 ContainerCreating 0 13s
httpd-replicaset-p8vdv 0/1 ContainerCreating 0 13s
httpd-replicaset-w4nmd 0/1 ContainerCreating 0 13s
--------------------------------------------------------------------------------------------------------------------------------------------
Task 38: 15/Feb/2022
Git Clone Repositories
DevOps team created a new Git repository last week; however, as of now no team is using it. The Nautilus application development team recently asked for a copy of that repo on Storage server in Stratos DC. Please clone the repo as per details shared below:
The repo that needs to be cloned is /opt/news.git
Clone this git repository under /usr/src/kodekloudrepos directory. Please do not try to make any changes in repo.
1. Login to Storage server an switch to root
ssh natasha@ststor01
sudo su -
2. Go to location where you want to clone the repository / destination and verify its empty
# cd /usr/src/kodekloudrepos/
# ll
total 0
3. Clone the repository using given location/source and verify the contents
# git clone /opt/news.git/
Cloning into 'news'...
warning: You appear to have cloned an empty repository.
done.
# ll
total 4
drwxr-xr-x 3 root root 4096 Feb 15 17:32 news
# cd news
# ll
total 0
--------------------------------------------------------------------------------------------------------------------------------------------
Task 39 : 17/Feb/2022
Setup Puppet Certs
The Nautilus DevOps team has set up a puppet master and an agent node in Stratos Datacenter. Puppet master is running on jump host itself (also note that Puppet master node is also running as Puppet CA server) and Puppet agent is running on App Server 2. Since it is a fresh set up, the team wants to sign certificates for puppet master as well as puppet agent nodes so that they can proceed with the next steps of set up. You can find more details about the task below:
Puppet server and agent nodes are already have required packages, but you may need to start puppetserver (on master) and puppet service on both nodes.
Assign and sign certificates for both master and agent node.
On Jump Host/PuppetMaster server :
1. Switch to root user
sudo su -
2. Make changes in /etc/hosts to include alias for puppet master
# vi /etc/hosts
172.16.238.3 jump_host.stratos.xfusioncorp.com jump_host puppet
172.16.239.5 jump_host.stratos.xfusioncorp.com jump_host puppet
172.17.0.4 jump_host.stratos.xfusioncorp.com jump_host puppet
# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.16.238.10 stapp01.stratos.xfusioncorp.com
172.16.238.11 stapp02.stratos.xfusioncorp.com
172.16.238.12 stapp03.stratos.xfusioncorp.com
172.16.238.3 jump_host.stratos.xfusioncorp.com jump_host puppet
172.16.239.5 jump_host.stratos.xfusioncorp.com jump_host puppet
172.17.0.4 jump_host.stratos.xfusioncorp.com jump_host puppet
3.Check puppetserver status
# systemctl status puppetserver
● puppetserver.service - puppetserver Service
Loaded: loaded (/usr/lib/systemd/system/puppetserver.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2022-02-17 04:34:20 UTC; 1min 11s ago
Process: 13195 ExecStart=/opt/puppetlabs/server/apps/puppetserver/bin/puppetserver start (code=exited, status=0/SUCCESS)
Main PID: 13258 (java)
Tasks: 90 (limit: 4915)
CGroup: /docker/9463a0d98965db0a54bc2af297eb82a9ef1abcbe227e26805fd5cf3cd02bdb53/system.slice/puppetserver.service
└─13258 /usr/bin/java -Xms512m -Xmx512m -Djruby.logger.class=com.puppetlabs.jruby_utils.jruby.Slf4jLogger -XX:OnOutOfMemoryErro...
4. Check certificates on puppetserver
# puppetserver ca list --all
Signed Certificates:
964369dd618d.c.argo-prod-us-east1.internal (SHA256) 8C:19:47:FD:59:97:CE:0C:1D:DF:52:92:A3:BA:41:22:F2:3D:95:D4:38:D9:EF:85:65:9A:7B:B5:59:D5:CA:E6 alt names: ["DNS:puppet", "DNS:964369dd618d.c.argo-prod-us-east1.internal"] authorization extensions: [pp_cli_auth: true]
jump_host.stratos.xfusioncorp.com (SHA256) F1:1F:B0:FE:F6:4A:20:52:C4:C7:D6:9E:1B:FC:2E:32:21:8C:53:5E:E3:61:9F:A1:47:B9:A9:78:2F:E5:3D:66 alt names: ["DNS:puppet", "DNS:jump_host.stratos.xfusioncorp.com"] authorization extensions: [pp_cli_auth: true]
On App server/PuppeetClient :
5. Login to App server and switch to root
ssh steve@stapp02
sudo su -
6. Make the PuppetServer Master entries in /etc/hosts file
# vi /etc/hosts
172.16.238.3 jump_host.stratos.xfusioncorp.com jump_host puppet
172.16.239.5 jump_host.stratos.xfusioncorp.com jump_host puppet
172.17.0.4 jump_host.stratos.xfusioncorp.com jump_host puppet
7. Verify hosts entries via ping
# ping puppet
PING jump_host.stratos.xfusioncorp.com (172.16.238.3) 56(84) bytes of data.
64 bytes from jump_host.stratos.xfusioncorp.com (172.16.238.3): icmp_seq=1 ttl=64 time=0.068 ms
64 bytes from jump_host.stratos.xfusioncorp.com (172.16.238.3): icmp_seq=2 ttl=64 time=0.076 ms
64 bytes from jump_host.stratos.xfusioncorp.com (172.16.238.3): icmp_seq=3 ttl=64 time=0.071 ms
64 bytes from jump_host.stratos.xfusioncorp.com (172.16.238.3): icmp_seq=4 ttl=64 time=0.072 ms
64 bytes from jump_host.stratos.xfusioncorp.com (172.16.238.3): icmp_seq=5 ttl=64 time=0.090 ms
^C
--- jump_host.stratos.xfusioncorp.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4081ms
rtt min/avg/max/mdev = 0.068/0.075/0.090/0.011 ms
8. Check puppet client status and check if errors
# systemctl status puppet
● puppet.service - Puppet agent
Loaded: loaded (/usr/lib/systemd/system/puppet.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2022-02-17 04:31:58 UTC; 6min ago
Main PID: 487 (puppet)
CGroup: /docker/a819efbba5ee93fe68e7e03589eeef739764d9d47a85c8db98909ab600c248bc/system.slice/puppet.service
└─487 /opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/puppet/bin/puppet agent --no-daemonize
Feb 17 04:31:58 stapp02.stratos.xfusioncorp.com systemd[1]: About to execute: /opt/puppetlabs/puppet/bin/puppet agent $PUPPET_EXTRA_...monize
Feb 17 04:31:58 stapp02.stratos.xfusioncorp.com systemd[1]: Forked /opt/puppetlabs/puppet/bin/puppet as 487
Feb 17 04:31:58 stapp02.stratos.xfusioncorp.com systemd[1]: puppet.service changed dead -> running
Feb 17 04:31:58 stapp02.stratos.xfusioncorp.com systemd[1]: Job puppet.service/start finished, result=done
Feb 17 04:31:58 stapp02.stratos.xfusioncorp.com systemd[1]: Started Puppet agent.
Feb 17 04:31:58 stapp02.stratos.xfusioncorp.com systemd[487]: Executing: /opt/puppetlabs/puppet/bin/puppet agent --no-daemonize
Feb 17 04:34:20 stapp02.stratos.xfusioncorp.com puppet-agent[487]: Request to https://puppet:8140/puppet-ca/v1 timed out connect oper...conds
Feb 17 04:34:20 stapp02.stratos.xfusioncorp.com puppet-agent[487]: Wrapped exception:
Feb 17 04:34:20 stapp02.stratos.xfusioncorp.com puppet-agent[487]: execution expired
Feb 17 04:34:20 stapp02.stratos.xfusioncorp.com puppet-agent[487]: No more routes to ca
Hint: Some lines were ellipsized, use -l to show in full.
9. Restart puppet client and check status
# systemctl restart puppet
# systemctl status puppet
● puppet.service - Puppet agent
Loaded: loaded (/usr/lib/systemd/system/puppet.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2022-02-17 04:38:12 UTC; 3s ago
Main PID: 596 (puppet)
CGroup: /docker/a819efbba5ee93fe68e7e03589eeef739764d9d47a85c8db98909ab600c248bc/system.slice/puppet.service
└─596 /opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/puppet/bin/puppet agent --no-daemonize
Feb 17 04:38:12 stapp02.stratos.xfusioncorp.com systemd[1]: About to execute: /opt/puppetlabs/puppet/bin/puppet agent $PUPPET_EXTRA_...monize
Feb 17 04:38:12 stapp02.stratos.xfusioncorp.com systemd[1]: Forked /opt/puppetlabs/puppet/bin/puppet as 596
Feb 17 04:38:12 stapp02.stratos.xfusioncorp.com systemd[1]: puppet.service changed dead -> running
Feb 17 04:38:12 stapp02.stratos.xfusioncorp.com systemd[1]: Job puppet.service/start finished, result=done
Feb 17 04:38:12 stapp02.stratos.xfusioncorp.com systemd[1]: Started Puppet agent.
Feb 17 04:38:12 stapp02.stratos.xfusioncorp.com systemd[596]: Executing: /opt/puppetlabs/puppet/bin/puppet agent --no-daemonize
Hint: Some lines were ellipsized, use -l to show in full.
On Jump Host/PuppetMaster Server :
10. Check certificates on puppetserver and look for stapp02 certificate request
# puppetserver ca list --all
Requested Certificates:
stapp02.stratos.xfusioncorp.com (SHA256) 8F:E9:B3:29:D6:8C:83:7D:47:3F:03:0C:F0:F2:06:18:E1:60:00:47:5F:C3:D0:00:68:4B:B9:6A:BC:99:5F:DB
Signed Certificates:
964369dd618d.c.argo-prod-us-east1.internal (SHA256) 8C:19:47:FD:59:97:CE:0C:1D:DF:52:92:A3:BA:41:22:F2:3D:95:D4:38:D9:EF:85:65:9A:7B:B5:59:D5:CA:E6 alt names: ["DNS:puppet", "DNS:964369dd618d.c.argo-prod-us-east1.internal"] authorization extensions: [pp_cli_auth: true]
jump_host.stratos.xfusioncorp.com (SHA256) F1:1F:B0:FE:F6:4A:20:52:C4:C7:D6:9E:1B:FC:2E:32:21:8C:53:5E:E3:61:9F:A1:47:B9:A9:78:2F:E5:3D:66 alt names: ["DNS:puppet", "DNS:jump_host.stratos.xfusioncorp.com"] authorization extensions: [pp_cli_auth: true]
11. Sign all certificates
# puppetserver ca sign --all
Successfully signed certificate request for stapp02.stratos.xfusioncorp.com
On App server/PuppetClient :
12. Validate puppet agent sign on
# puppet agent -t
Info: csr_attributes file loading from /etc/puppetlabs/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for stapp02.stratos.xfusioncorp.com
Info: Certificate Request fingerprint (SHA256): 8F:E9:B3:29:D6:8C:83:7D:47:3F:03:0C:F0:F2:06:18:E1:60:00:47:5F:C3:D0:00:68:4B:B9:6A:BC:99:5F:DB
Info: Downloaded certificate for stapp02.stratos.xfusioncorp.com from https://puppet:8140/puppet-ca/v1
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for stapp02.stratos.xfusioncorp.com
Info: Applying configuration version '1645072754'
Info: Creating state file /opt/puppetlabs/puppet/cache/state/state.yaml
Notice: Applied catalog in 0.01 seconds
--------------------------------------------------------------------------------------------------------------------------------------------
Task 40 : 24/Feb/2022
Ansible Setup Httpd and PHP
Nautilus Application development team wants to test the Apache and PHP setup on one of the app servers in Stratos Datacenter. They want the DevOps team to prepare an Ansible playbook to accomplish this task. Below you can find more details about the task.
There is an inventory file ~/playbooks/inventory on jump host.
Create a playbook ~/playbooks/httpd.yml on jump host and perform the following tasks on App Server 1.
a. Install httpd and php packages (whatever default version is available in yum repo).
b. Change default document root of Apache to /var/www/html/myroot in default Apache config /etc/httpd/conf/httpd.conf. Make sure /var/www/html/myroot path exists (if not please create the same).
c. There is a template ~/playbooks/templates/phpinfo.php.j2 on jump host. Copy this template to the Apache document root you created as phpinfo.php file and make sure user owner and the group owner for this file is apache user.
d. Start and enable httpd service.
Note: Validation will try to run the playbook using command ansible-playbook -i inventory httpd.yml, so please make sure the playbook works this way without passing any extra arguments.
thor@jump_host ~$ cd playbooks/
thor@jump_host ~/playbooks$ ll -a
total 20
drwxr-xr-x 3 thor thor 4096 Feb 24 05:10 .
drwxr----- 1 thor thor 4096 Feb 24 05:10 ..
-rw-r--r-- 1 thor thor 36 Feb 24 05:10 ansible.cfg
-rw-r--r-- 1 thor thor 237 Feb 24 05:10 inventory
drwxr-xr-x 2 thor thor 4096 Feb 24 05:10 templates
thor@jump_host ~/playbooks$ cd inventory
bash: cd: inventory: Not a directory
thor@jump_host ~/playbooks$ ll -a
total 20
drwxr-xr-x 3 thor thor 4096 Feb 24 05:10 .
drwxr----- 1 thor thor 4096 Feb 24 05:10 ..
-rw-r--r-- 1 thor thor 36 Feb 24 05:10 ansible.cfg
-rw-r--r-- 1 thor thor 237 Feb 24 05:10 inventory
drwxr-xr-x 2 thor thor 4096 Feb 24 05:10 templates
thor@jump_host ~/playbooks$ vi httpd.yml
thor@jump_host ~/playbooks$
thor@jump_host ~/playbooks$
thor@jump_host ~/playbooks$ cat httpd.yml
- name: Setup Httpd and PHP
hosts: stapp01
become: yes
tasks:
- name: Install latest version of httpd and php
package:
name:
- httpd
- php
state: latest
- name: Replace default DocumentRoot in httpd.conf
replace:
path: /etc/httpd/conf/httpd.conf
regexp: DocumentRoot \"\/var\/www\/html\"
replace: DocumentRoot "/var/www/html/myroot"
- name: Create the new DocumentRoot directory if it does not exist
file:
path: /var/www/html/myroot
state: directory
owner: apache
group: apache
- name: Use Jinja2 template to generate phpinfo.php
template:
src: /home/thor/playbooks/templates/phpinfo.php.j2
dest: /var/www/html/myroot/phpinfo.php
owner: apache
group: apache
- name: Start and enable service httpd
service:
name: httpd
state: started
enabled: yes
thor@jump_host ~/playbooks$
thor@jump_host ~/playbooks$
thor@jump_host ~/playbooks$
thor@jump_host ~/playbooks$ cd templates/
thor@jump_host ~/playbooks/templates$ ll-a
bash: ll-a: command not found
thor@jump_host ~/playbooks/templates$ ll -a
total 12
drwxr-xr-x 2 thor thor 4096 Feb 24 05:10 .
drwxr-xr-x 3 thor thor 4096 Feb 24 05:13 ..
-rw-r--r-- 1 thor thor 19 Feb 24 05:10 phpinfo.php.j2
thor@jump_host ~/playbooks/templates$ cd ../
thor@jump_host ~/playbooks$ ansible-playbook -i inventory httpd.yml
PLAY [Setup Httpd and PHP] ******************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************
ok: [stapp01]
TASK [Install latest version of httpd and php] **********************************************************************************************
changed: [stapp01]
TASK [Replace default DocumentRoot in httpd.conf] *******************************************************************************************
changed: [stapp01]
TASK [Create the new DocumentRoot directory if it does not exist] ***************************************************************************
changed: [stapp01]
TASK [Use Jinja2 template to generate phpinfo.php] ******************************************************************************************
changed: [stapp01]
TASK [Start and enable service httpd] *******************************************************************************************************
changed: [stapp01]
PLAY RECAP **********************************************************************************************************************************
stapp01 : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
thor@jump_host ~/playbooks$
Last login: Thu Feb 24 05:10:23 UTC 2022 on pts/0
thor@jump_host ~$ ssh tony@stapp01
The authenticity of host 'stapp01 (172.16.238.10)' can't be established.
ECDSA key fingerprint is SHA256:HRK4JT6fwc3O4QN4Kd4nKBfOFgvwjBs/XBj+WP8m56Y.
ECDSA key fingerprint is MD5:46:21:7e:34:9a:50:9c:45:12:9f:ba:d6:de:ac:ed:db.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'stapp01' (ECDSA) to the list of known hosts.
tony@stapp01's password:
Last login: Thu Feb 24 05:15:26 2022 from jump_host.devops-ansible-httpd-php-v2_app_net
[tony@stapp01 ~]$
[tony@stapp01 ~]$
[tony@stapp01 ~]$ sudo su -
[root@stapp01 ~]# Ir0nM@n
-bash: Ir0nM@n: command not found
[root@stapp01 ~]#
[root@stapp01 ~]#
[root@stapp01 ~]#
[root@stapp01 ~]#
[root@stapp01 ~]#
[root@stapp01 ~]#
[root@stapp01 ~]# rpm -qa |grep httpd
httpd-tools-2.4.6-97.el7.centos.4.x86_64
httpd-2.4.6-97.el7.centos.4.x86_64
[root@stapp01 ~]# rpm -qa |grep php
php-cli-5.4.16-48.el7.x86_64
php-common-5.4.16-48.el7.x86_64
php-5.4.16-48.el7.x86_64
[root@stapp01 ~]#
[root@stapp01 ~]#
[root@stapp01 ~]# cd /var/www/html/
[root@stapp01 html]# ls -ahl
total 12K
drwxr-xr-x 3 root root 4.0K Feb 24 05:15 .
drwxr-xr-x 4 root root 4.0K Feb 24 05:15 ..
drwxr-xr-x 2 apache apache 4.0K Feb 24 05:15 myroot
[root@stapp01 html]#
--------------------------------------------------------------------------------------------------------------------------------------------
Task 41 : 25/Feb/2022
Ansible File Module
The Nautilus DevOps team is working to test several Ansible modules on servers in Stratos DC. Recently they wanted to test the file creation on remote hosts using Ansible. Find below more details about the task:
a. Create an inventory file ~/playbook/inventory on jump host and add all app servers in it.
b. Create a playbook ~/playbook/playbook.yml to create a blank file /opt/nfsshare.txt on all app servers.
c. The /opt/nfsshare.txt file permission must be 0755.
d. The user/group owner of file /opt/nfsshare.txt must be tony on app server 1, steve on app server 2 and banner on app server 3.
Note: Validation will try to run the playbook using command ansible-playbook -i inventory playbook.yml, so please make sure the playbook works this way without passing any extra arguments.
1. Got to playbook directory
cd playbook/
pwd
/home/thor/playbook
2. Create the inventory file as per given requirements and verify
ll -a
total 8
drwxr-xr-x 2 thor thor 4096 Feb 25 09:14 .
drwxr----- 1 thor thor 4096 Feb 25 09:14 ..
vi inventory
stapp01 ansible_host=172.16.238.10 ansible_ssh_pass=Ir0nM@n ansible_user=tony
stapp02 ansible_host=172.16.238.11 ansible_ssh_pass=Am3ric@ ansible_user=steve
stapp03 ansible_host=172.16.238.12 ansible_ssh_pass=BigGr33n ansible_user=banner
cat inventory
stapp01 ansible_host=172.16.238.10 ansible_ssh_pass=Ir0nM@n ansible_user=tony
stapp02 ansible_host=172.16.238.11 ansible_ssh_pass=Am3ric@ ansible_user=steve
stapp03 ansible_host=172.16.238.12 ansible_ssh_pass=BigGr33n ansible_user=banner
3. Verify if ansible is able to connect as per inventory file
ansible all -a "ls -ahl /opt/nfsshare.txt" -i inventory
stapp03 | FAILED | rc=2 >>
ls: cannot access /opt/nfsshare.txt: No such file or directorynon-zero return code
stapp02 | FAILED | rc=2 >>
ls: cannot access /opt/nfsshare.txt: No such file or directorynon-zero return code
stapp01 | FAILED | rc=2 >>
ls: cannot access /opt/nfsshare.txt: No such file or directorynon-zero return code
4. Create playbook.yml file as per requirements and verify
vi playbook.yml
- name: Create file in appservers
hosts: stapp01, stapp02, stapp03
become: yes
tasks:
- name: Create the file and set properties
file:
path: /opt/nfsshare.txt
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0755"
state: touch
cat playbook.yml
- name: Create file in appservers
hosts: stapp01, stapp02, stapp03
become: yes
tasks:
- name: Create the file and set properties
file:
path: /opt/nfsshare.txt
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0755"
state: touch
5. Run the playbook
ansible-playbook -i inventory playbook.yml
PLAY [Create file in appservers] ************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************
ok: [stapp03]
ok: [stapp02]
ok: [stapp01]
TASK [Create the file and set properties] ***************************************************************************************************
changed: [stapp01]
changed: [stapp03]
changed: [stapp02]
PLAY RECAP **********************************************************************************************************************************
stapp01 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
stapp02 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
stapp03 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
6. Verify the files created on App servers
ansible all -a "ls -ahl /opt/nfsshare.txt" -i inventory
stapp01 | CHANGED | rc=0 >>
-rwxr-xr-x 1 tony tony 0 Feb 25 09:20 /opt/nfsshare.txt
stapp03 | CHANGED | rc=0 >>
-rwxr-xr-x 1 banner banner 0 Feb 25 09:20 /opt/nfsshare.txt
stapp02 | CHANGED | rc=0 >>
-rwxr-xr-x 1 steve steve 0 Feb 25 09:20 /opt/nfsshare.txt
--------------------------------------------------------------------------------------------------------------------------------------------
Task 42: 4/Mar/2022
Troubleshoot Deployment issues in Kubernetes
Last week, the Nautilus DevOps team deployed a redis app on Kubernetes cluster, which was working fine so far. This morning one of the team members was making some changes in this existing setup, but he made some mistakes and the app went down. We need to fix this as soon as possible. Please take a look.
The deployment name is redis-deployment. The pods are not in running state right now, so please look into the issue and fix the same.
Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
thor@jump_host ~$ kubectl get-deployment
Error: unknown command "get-deployment" for "kubectl"
Run 'kubectl --help' for usage.
thor@jump_host ~$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
redis-deployment 0/1 1 0 71s
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-deployment-8bdf985f7-65g4j 0/1 ContainerCreating 0 106s
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get configmap
NAME DATA AGE
kube-root-ca.crt 1 20m
redis-config 2 2m4s
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl describe deployment
Name: redis-deployment
Namespace: default
CreationTimestamp: Fri, 04 Mar 2022 07:59:44 +0000
Labels: app=redis
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=redis
Replicas: 1 desired | 1 updated | 1 total | 0 available | 1 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=redis
Containers:
redis-container:
Image: redis:alpin
Port: 6379/TCP
Host Port: 0/TCP
Requests:
cpu: 300m
Environment: <none>
Mounts:
/redis-master from config (rw)
/redis-master-data from data (rw)
Volumes:
data:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:
SizeLimit: <unset>
config:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: redis-conig
Optional: false
Conditions:
Type Status Reason
---- ------ ------
Available False MinimumReplicasUnavailable
Progressing True ReplicaSetUpdated
OldReplicaSets: redis-deployment-8bdf985f7 (1/1 replicas created)
NewReplicaSet: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 2m45s deployment-controller Scaled up replica set redis-deployment-8bdf985f7 to 1
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl describe pods
Name: redis-deployment-8bdf985f7-65g4j
Namespace: default
Priority: 0
Node: kodekloud-control-plane/172.17.0.2
Start Time: Fri, 04 Mar 2022 07:59:44 +0000
Labels: app=redis
pod-template-hash=8bdf985f7
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: ReplicaSet/redis-deployment-8bdf985f7
Containers:
redis-container:
Container ID:
Image: redis:alpin
Image ID:
Port: 6379/TCP
Host Port: 0/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Requests:
cpu: 300m
Environment: <none>
Mounts:
/redis-master from config (rw)
/redis-master-data from data (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-mktdc (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
data:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:
SizeLimit: <unset>
config:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: redis-conig
Optional: false
default-token-mktdc:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-mktdc
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 3m38s default-scheduler Successfully assigned default/redis-deployment-8bdf985f7-65g4j to kodekloud-control-plane
Warning FailedMount 95s kubelet Unable to attach or mount volumes: unmounted volumes=[config], unattached volumes=[data config default-token-mktdc]: timed out waiting for the condition
Warning FailedMount 90s (x9 over 3m37s) kubelet MountVolume.SetUp failed for volume "config" : configmap "redis-conig" not found
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl describe configmap
Name: kube-root-ca.crt
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
ca.crt:
----
-----BEGIN CERTIFICATE-----
MIIC5zCCAc+gAwIBAgIBADANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwprdWJl
cm5ldGVzMB4XDTIyMDMwNDA3MzkxMVoXDTMyMDMwMTA3MzkxMVowFTETMBEGA1UE
AxMKa3ViZXJuZXRlczCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALme
RU36Jbasf+ky0j2DuqdVD+2Vw1trKQnA4N5n/gFzvKFUu4d6ZW0lWNyd73f/0W4U
y9joi+Pp2WZX5wEbwyTbJZ9RYopm8rgRRg1V1+GU4mC5aBUrat4pjQZX4OQNyBMd
ZBz/Cll/c/S6Y1vTDeqOm4SYz+2YSyVOtdLtBnUDGxH6m13gfqrGN/n/RhlDJO9T
722YgASeOFvPXpJMzStK/lZjUcsW4EYNoQgKewn+yB5k2LTvhs3ovj5Mc0gbWMBn
azJgCen+EJAV2yFxuFf41ppi1MvY7CeytGuOnv3uNi609TJrlp7NEuSoMCeIt1gT
IcaNpsFGFJ8CiOFWjgsCAwEAAaNCMEAwDgYDVR0PAQH/BAQDAgKkMA8GA1UdEwEB
/wQFMAMBAf8wHQYDVR0OBBYEFJ6FKF3kj6rXegz1wkfzx09gxROjMA0GCSqGSIb3
DQEBCwUAA4IBAQCuOE/yWOW7NAZAgYCavM8gd+px/onSM9o43wcl7YSvFM6/TVDq
ksbpbdG60GmgV5Fggui6p+zaaAYrtY33qRIYKwvQ0rpEx04llQRETrvXyXCtAe83
zYteCjlbY0rlpjWhpxxXS0RJLilMojtbi4Vr05zLEyYa5cQ1NN5YNgzGdFBHYY+D
bPvGVXFyVrzDdf8iUt9VcMOsrD03s7sUitnoIJSE+PkaYvdxcTuwENRccQTZoj6E
vfWAmEqPTVTYnkv6Z1lHejwXUoWd/DaVnmajUKB8YS2TgoUjwpEJbS0lRAikHeSs
zZiAqUXdZmZQXDWK6mlQELlg0u48IhGrHrF6
-----END CERTIFICATE-----
Events: <none>
Name: redis-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
maxmemory:
----
2mb
maxmemory-policy:
----
allkeys-lru
Events: <none>
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl edit deployment
deployment.apps/redis-deployment edited
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
redis-deployment 1/1 1 1 9m18s
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-deployment-5bb6dd57fd-l4l56 1/1 Running 0 46s
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
redis-deployment 1/1 1 1 9m33s
thor@jump_host ~$
--------------------------------------------------------------------------------------------------------------------------------------------
Task 43 : 12/Mar/2022
Deploy Grafana on Kubernetes Cluster
The Nautilus DevOps teams is planning to set up a Grafana tool to collect and analyze analytics from some applications. They are planning to deploy it on Kubernetes cluster. Below you can find more details.
1.) Create a deployment named grafana-deployment-nautilus using any grafana image for Grafana app. Set other parameters as per your choice.
2.) Create NodePort type service with nodePort 32000 to expose the app.
You need not to make any configuration changes inside the Grafana app once deployed, just make sure you are able to access the Grafana login page.
Note: The kubeclt on jump_host has been configured to work with kubernetes cluster.
thor@jump_host ~$ kubectl get pods
No resources found in default namespace.
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h16m
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ vi /tmp/grafana.yaml
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ cat /tmp/grafana.yaml
apiVersion: v1
kind: Service
metadata:
name: grafana-service-nautilus
spec:
type: NodePort
selector:
app: grafana
ports:
- port: 3000
targetPort: 3000
nodePort: 32000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana-deployment-nautilus
spec:
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
containers:
- name: grafana-container-nautilus
image: grafana/grafana:latest
ports:
- containerPort: 3000
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl create -f /tmp/grafana.yaml
service/grafana-service-nautilus created
deployment.apps/grafana-deployment-nautilus created
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana-service-nautilus NodePort 10.96.233.148 <none> 3000:32000/TCP 15s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h18m
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
grafana-deployment-nautilus-66bb8cdd8b-xkrwz 1/1 Running 0 22s
--------------------------------------------------------------------------------------------------------------------------------------------
Task 44 : 16/Mar/2022
Create Cronjobs in Kubernetes
There are some jobs/tasks that need to be run regularly on different schedules. Currently the Nautilus DevOps team is working on developing some scripts that will be executed on different schedules, but for the time being the team is creating some cron jobs in Kubernetes cluster with some dummy commands (which will be replaced by original scripts later). Create a cronjob as per details given below:
Create a cronjob named datacenter.
Set schedule to */8 * * * *.
Container name should be cron-datacenter.
Use nginx image with latest tag only and remember to mention the tag i.e nginx:latest.
Run a dummy command echo Welcome to xfusioncorp!.
Ensure restart policy is OnFailure.
Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
thor@jump_host ~$ kubectl get pods
No resources found in default namespace.
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get cronjobs
No resources found in default namespace.
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get cronjob
No resources found in default namespace.
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ vi /tmp/cron.yml
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ cat /tmp/cron.yml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: devops
spec:
schedule: "*/5 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: cron-devops
image: nginx:latest
command:
- /bin/sh
- -c
- echo Welcome to xfusioncorp!
restartPolicy: OnFailure
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl create -f /tmp/cron.yml
cronjob.batch/devops created
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get pods
No resources found in default namespace.
thor@jump_host ~$ kubectl get pod
No resources found in default namespace.
thor@jump_host ~$ kubectl get cronjob
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
devops */5 * * * * False 0 <none> 35s
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get pod
No resources found in default namespace.
thor@jump_host ~$ kubectl get pod
No resources found in default namespace.
thor@jump_host ~$ kubectl get pod
No resources found in default namespace.
thor@jump_host ~$ kubectl get cronjob
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
devops */5 * * * * False 0 <none> 61s
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$
thor@jump_host ~$ kubectl get cronjob
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
devops */5 * * * * False 0 <none> 67s
thor@jump_host ~$ kubectl get cronjob
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
devops */5 * * * * False 0 <none> 70s
thor@jump_host ~$ kubectl get cronjob
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
devops */5 * * * * False 1 15s 101s
thor@jump_host ~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
devops-1647415500-7jhh7 0/1 ContainerCreating 0 16s
thor@jump_host ~$ kubectl logs devops-1647415500-7jhh7