Friday, October 22, 2021

EKS : Kubernetes : AWS : Install Kubernetes on Control Plane and Configure EKS with kubectl

visudo
703250313 ALL=(ALL) NOPASSWD: ALL
eks                ALL=(ALL) NOPASSWD: ALL

export VISUAL=vim
export EDITOR="$VISUAL"


> Bootstrapping clusters with kubeadm
> Installing Kubernetes with kops
> Installing Kubernetes with Kubespray

Installing kubeadm, kubelet and kubectl
""""""""""You will install these packages on all of your machines:"""""""""
kubeadm: the command to bootstrap the cluster.
kubelet: the component that runs on all of the machines in your cluster and does things like starting pods and containers.
kubectl: the command line util to talk to your cluster.

apt-get install bash-completion
source /usr/share/bash-completion/bash_completion
type _init_completion
echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash >/etc/bash_completion.d/kubectl
kubectl completion bash


> sudo snap install kubectl --classic
> kubectl version --client

history | grep SEARCH_STRING


curl -o aws-iam-authenticator https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$PATH:$HOME/bin
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
aws-iam-authenticator help


find ./path/subpath searchFileName
Syntax :
$ find [where to start searching from]
 [expression determines what to find] [-options] [what to find]
 
 
 Instead of manually making 1 node as Kubenetes Master and rest as worker using "kubeadm" manually
 We go for EKS approach
 
 kubectl cluster-info
 kubectl 
 kubectl get pods
 
 
 eks@GRDLUSAWSJS01:~$ kubectl get deployment  -n fda
NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
analytics            1/1     1            1           378d
business-rules       1/1     1            1           330d
case-management      1/1     1            1           330d
classifiy-rule       1/1     1            1           378d
cora-mail            1/1     1            1           378d
data-processor       1/1     1            1           330d
doc-conversion-api   1/1     1            1           323d
eaas-service         1/1     1            1           378d
email-segmentator    1/1     1            1           378d
flowable             1/1     1            1           330d
genex-runtime        1/1     1            1           378d
ief-classification   1/1     1            1           377d
ief-extraction       1/1     1            1           377d
ief-tensorflow       1/1     1            1           377d
ml-webapp            1/1     1            1           332d
modelserver          1/1     1            1           378d
nlu-service          1/1     1            1           378d
ocr-nuance           1/1     1            1           378d
output-generation    1/1     1            1           330d
platform             1/1     1            1           330d
slot-modelserver     1/1     1            1           368d
slot-serving         1/1     1            1           368d
trainer              1/1     1            1           378d
usaaddress           1/1     1            1           330d
vea-cc               1/1     1            1           378d
vea-nlp              1/1     1            1           378d

eks@GRDLUSAWSJS01:~$ kubectl rollout history deployment vea-cc -n fda
deployment.apps/vea-cc
REVISION  CHANGE-CAUSE
1         <none>
2         <none>
3         <none>
4         <none>


eks@GRDLUSAWSJS01:~$ kubectl get nodes
NAME                            STATUS   ROLES    AGE    VERSION
ip-10-102-25-101.ec2.internal   Ready    <none>   151d   v1.17.9-eks-4c6976
ip-10-102-25-105.ec2.internal   Ready    <none>   274d   v1.17.9-eks-4c6976
ip-10-102-25-142.ec2.internal   Ready    <none>   69d    v1.17.9-eks-4c6976
ip-10-102-25-143.ec2.internal   Ready    <none>   179d   v1.17.9-eks-4c6976
ip-10-102-25-149.ec2.internal   Ready    <none>   330d   v1.17.9-eks-4c6976
ip-10-102-25-186.ec2.internal   Ready    <none>   260d   v1.17.9-eks-4c6976
ip-10-102-25-247.ec2.internal   Ready    <none>   260d   v1.17.9-eks-4c6976
ip-10-102-25-29.ec2.internal    Ready    <none>   302d   v1.17.9-eks-4c6976
ip-10-102-25-31.ec2.internal    Ready    <none>   326d   v1.17.9-eks-4c6976
ip-10-102-25-40.ec2.internal    Ready    <none>   260d   v1.17.9-eks-4c6976
ip-10-102-26-106.ec2.internal   Ready    <none>   330d   v1.17.9-eks-4c6976
ip-10-102-26-111.ec2.internal   Ready    <none>   330d   v1.17.9-eks-4c6976
ip-10-102-26-55.ec2.internal    Ready    <none>   179d   v1.17.9-eks-4c6976
ip-10-102-26-58.ec2.internal    Ready    <none>   233d   v1.17.9-eks-4c6976
ip-10-102-26-74.ec2.internal    Ready    <none>   179d   v1.17.9-eks-4c6976
ip-10-102-26-88.ec2.internal    Ready    <none>   164d   v1.17.9-eks-4c6976


eks@GRDLUSAWSJS01:~$ kubectl cluster-info
Kubernetes master is running at https://23BB04FB3E3508D16899825B2B3F38FA.yl4.us-east-1.eks.amazonaws.com
CoreDNS is running at https://23BB04FB3E3508D16899825B2B3F38FA.yl4.us-east-1.eks.amazonaws.com/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://23BB04FB3E3508D16899825B2B3F38FA.yl4.us-east-1.eks.amazonaws.com/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
eks@GRDLUSAWSJS01:~$


Linux : PING - Internet Speed Test : 8.8.8.8 - Google DNS

https://wisetut.com/best-ping-test-ip-addresses-google-dns-8-8-8-8-cloudflare-dns-1-1-1-1/


The network connection to the 8.8.8.8 Google DNS service can be tested with the ping command like below.

$ ping 8.8.8.8

The output is like below as we can see that the time or RTT is very low.

Linux : Ubuntu - APT vs SNAP

https://phoenixnap.com/kb/snap-vs-apt

Linux:/etc/shells or /etc/os-release

 eks@GRDLUSAWSAMUT01:~$ cat /etc/os-release

NAME="Ubuntu"

VERSION="18.04.6 LTS (Bionic Beaver)"

ID=ubuntu

ID_LIKE=debian

PRETTY_NAME="Ubuntu 18.04.6 LTS"

VERSION_ID="18.04"

HOME_URL="https://www.ubuntu.com/"

SUPPORT_URL="https://help.ubuntu.com/"

BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"

PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"

VERSION_CODENAME=bionic

UBUNTU_CODENAME=bionic

eks@GRDLUSAWSAMUT01:~$ cat /etc/shells

# /etc/shells: valid login shells

/bin/sh

/bin/bash

/bin/rbash

/bin/dash

/usr/bin/tmux

/usr/bin/screen

eks@GRDLUSAWSAMUT01:~$


Linux:Kubectl : Add New User: Add User to secondary group : Change default Shell of a user

https://linuxize.com/post/how-to-create-users-in-linux-using-the-useradd-command/ 

sudo useradd -m username

ls -la /home/username/

https://careerkarma.com/blog/linux-add-user-to-group/

sudo usermod -a -G group_to_add username


https://www.tecmint.com/change-a-users-default-shell-in-linux/

 usermod --shell /bin/bash tecmint



admin@MACHINEVM01:~$ hostname -I

10.102.25.95 172.17.0.1 172.19.0.1

admin@MACHINEVM01:~$ getent passwd|grep admin

admin:*:16777219:16777220:Kaw, Karan:/home/admin:/bin/bash

admin@MACHINEVM01:~$ getent group|grep docker

docker:x:118:

admin@MACHINEVM01:~$ groups admin

admin : domain users BUILTIN\users

admin@MACHINEVM01:~$ sudo useradd -m eks

[sudo] password for admin:

admin@MACHINEVM01:~$ groups eks

eks : eks

admin@MACHINEVM01:~$ id eks

uid=1006(eks) gid=1006(eks) groups=1006(eks)

admin@MACHINEVM01:~$ getent group|grep eks

eks:x:1006:

admin@MACHINEVM01:~$ getent passwd|grep eks

eks:x:1006:1006::/home/eks:/bin/sh

admin@MACHINEVM01:~$ sudo usermod -a -G docker eks

admin@MACHINEVM01:~$ getent passwd|grep eks

eks:x:1006:1006::/home/eks:/bin/sh

admin@MACHINEVM01:~$ groups eks

eks : eks docker

admin@MACHINEVM01:~$


Docker-Compose Comands


apt install docker.io

apt install docker-compose


docker-compose up

docker-compose up -d


docker image ls

docker container ls


======================

docker ps

docker images

docker-compose -f docker-compose.yml down

docker-compose -f docker-compose.yml up -d


 netstat -tulpn|grep LISTEN

 

 tail -f nohup.out



 

Thursday, October 21, 2021

Linux : Bash-Completion :Kubernetes

kubernetes.io/docs/tasks/tools/included/optional-kubectl-configs-bash-linux/


apt-get install bash-completion or yum install bash-completion


o find out, reload your shell and run type _init_completion. If the command succeeds, you're already set, otherwise add the following to your ~/.bashrc file:

source /usr/share/bash-completion/bash_completion


The kubectl completion script for Bash can be generated with the command 

kubectl completion bash


 kubectl rollout history deployment vea-cc  -n fda



Tuesday, October 19, 2021

Linux: SSH:Password for Few Users

https://serverfault.com/questions/285800/how-to-disable-ssh-login-with-password-for-some-users


/etc/ssh/sshd_config
Match User <username>
PasswordAuthentication yes
Match all

EC2: TAG : Shutdown

Instance Schedule

09:00 - 21:00 Mon - Sun

AWS : Userdata after every restart

aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/
https://serverfault.com/questions/797482/how-to-make-ec2-user-data-script-run-again-on-startup


Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [scripts-user, always]

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"

#!/bin/bash
/bin/echo "Hello World" >> /tmp/testfile.txt
--//--

Monday, October 18, 2021

AWS : Userdata - Bash Script Fired Once

https://aws.amazon.com/premiumsupport/knowledge-center/ec2-user-account-cloud-init-user-data/

docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#retrieving-the-public-key

github.com/Cloud-Yeti/aws-ec2-course/blob/master/labs/lab07-ec2-userdata-ssh-with-password.MD


aws.amazon.com/blogs/aws/troubleshoot-boot-and-networking-issues-with-new-ec2-serial-console/

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html

#!/bin/bash
sed 's/PasswordAuthentication no/PasswordAuthentication yes/' -i /etc/ssh/sshd_config
systemctl restart sshd
service sshd restart


#TODO: replace bob with your desired username
useradd bob
# TODO: replace password123 with desired password and change bob to your username chosen in useradd 
echo "password123" | passwd --stdin bob

------------------------------------------------------------------------------
!/bin/bash
sed 's/PasswordAuthentication no/PasswordAuthentication yes/' -i /etc/ssh/sshd_config
service sshd restart
echo "admin@123" | passwd --stdin root



AWS : SSH Issue - Permission denied

https://stackoverflow.com/questions/36300446/ssh-permission-denied-publickey-gssapi-with-mic


 (publickey,gssapi-keyex,gssapi-with-mic).

ssh -i "CCA_Product.pem" ec2-user@10.79.197.206


docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#how-to-generate-your-own-key-and-import-it-to-aws

ssh-keygen -m PEM

pem

pub


awsfeed.com/uncategorized/using-ec2-serial-console-to-access-the-grub-menu-and-recover-from-boot-failures


docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-to-serial-console.html#sc-connection-methods


Push your SSH public key to the instance to start a serial console session

aws ec2-instance-connect send-serial-console-ssh-public-key \

    --instance-id i-06a0d8564550494b0 \

    --serial-port 0 \

    --ssh-public-key file://serialAccess.pub \

    --region us-east-1

Connect to the serial console using your private key

ssh -i serialAccess i-06a0d8564550494b0.port0@serial-console.ec2-instance-connect.us-east-1.aws

i-06a0d8564550494b0

Linux : KDE Neon

https://linuxhint.com/install-kde-neon-oracle-virtualbox/


KDE Neon --- Derivative of Ubuntu Linux

Konsole ---- Transparent 

LINUX:TMUX

https://youtu.be/l-lcd1MrSLM

tecmint.com/tmux-to-access-multiple-linux-terminals-inside-a-single-console/

https://askubuntu.com/questions/850055/ctrl-b-c-n-w-etc-not-working-in-tmux-console

https://ostechnix.com/tmux-command-examples-to-manage-multiple-terminal-sessions

https://www.networkworld.com/article/3545370/how-to-use-tmux-to-create-a-multi-pane-linux-terminal-window.htm

tmux

ctrl+b     and  Shift+%    :::  Split Vertically

ctrl+b     and  Shift+"     :::  Split Horizontally

Type "exit" from a particular window To kill that window/screen 

ctrl+b     and  d     :::  End Session

for example, to create a new terminal hold ctrl+b and release it then press shift+5 (%)

Wednesday, October 6, 2021

Maven : Snippet to copy all dependencies in 1 Folder

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-dependency-plugin</artifactId>
	<version>3.1.2</version>
	<executions>
		<execution>
			<id>copy-dependancies-to-libs</id>
			<phase>package</phase>
			<goals>
				<goal>copy-dependencies</goal>
			</goals>
			<configuration>
				<outputDirectory>${project.parent.basedir}/dependent-libs</outputDirectory>
				<overWriteReleases>false</overWriteReleases>
				<overWriteSnapshots>false</overWriteSnapshots>
				<overWriteIfNewer>true</overWriteIfNewer>
			</configuration>
		</execution>
	</executions>
</plugin>

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass