Wednesday, February 9, 2022

Day9 - kubernetes pod, configmap, statelful

 2/09/2022 - Class Notes
ReCap from last class
Configmap
Probes
PV
PVC
Storage class
----------------
Todays agent
create container
 - statefulset
 - helm
 - cronjobs
 - Stateful set
AWs authentication
- EBS volume
- PVC
read about 
job
initcontainer
daemonset

===============
nebulawsworks.com/insights/posts/leaveraging-aws-ens-for-kubernetes-persistent-volumes
- try to use ansible/terraform to recreate your cluster.
- using the tool, you can create and destroy rather then  manual tasks. 
---------------------------
Job and service
job - executes command/script one time. its an one time job. How do we run a particular command in job?
what is job in k8s?
A Job creates one or more Pods and will continue to retry execution of the Pods until a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions.

pod
images
-------
marvel
perl
ruby
python
How to run the image one time?
$ docker run python python abc.py
$ docker run <python-image> python abc.py
https://kubernetes.io/docs/concepts/workloads/controllers/job/
Read this link line by line
$ vi job.yml
apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4
$ kc apply -f job.yml
$ kc describe
$ kc logs $pods
$ kubectl apply -f job.yml
$ kc get pod --watch
$ kc get pods
pods are created
$ kc logs pi-rdf5t
CLean up finished jobs automatically
- cronjobs
TTL mechanism for finished jobs
https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/
crontab.guru
$ cat cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
$ kc apply -f cronjob.yaml
$ kc get svc -n kubernetes-dashboard
31617
httpS://get-the-nodeIP:port
[00:27:00]

$ kc get cronjob
$ kc delete confjob hello
check on k8s dashboard

cleanup all the executed/completed jobs for every 12 hours.
$ kc delete jobs name
initcontainer
-------------
sidecar
configmap -> we are injecting data to the pod using config object. But the data is static. 
static vs dynamic
static -> manual -> persistance volume
dynamic -> wihtout your intervention.
we want dynamic data or dependensive data.
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
Init containers are exactly like regular containers, except:
Init containers always run to completion.
Each init container must complete successfully before the next one starts.
If a Pod's init container fails, the kubelet repeatedly restarts that init container until it succeeds. However, if the Pod has a restartPolicy of Never, and an init container fails during startup of that Pod, Kubernetes treats the overall Pod as failed.

google "ansible awx docker compose"
https://github.com/geerlingguy/awx-container/blob/master/docker-compose.yml
$ cat initcontainer.yml
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
  - name: init-mydb
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]

- resource limit
  - cup/mem you can specify to container definition parameter...

baackground pods
- I don't want to access pod, but want them to be running like agent.
backup, log collector, garbage collector, metrics collectors
lets say we have log generated and need to forward to some other location. 
this kind of service, we call it daemonset in k8s.
logs - any issue, any transaction failed.
metrics -> resource utilization

initcontainer
- dynamically give data to your container ics init container while booting
 sidecar docker, 
A sidecar is a utility container in a pod that's loosely coupled to the main application container. 

Deploy jenkins as a pod?
What is disadvantage to run as a replica?
- replica can't work on this jenkins schenario because jenkins is going to use the filesystem.
- jenkins does not support active/active sesssion
lets take a database.
mysql pod -> deploy
as usual it usage pv, if you want to create a replica, how it is going to do?
if it was web appliation, its going to use multiple replicas.
if its a stateless application, we could use. even it shuffel between the nodes, we can still use. most frontend application, we can use it. it does not keep any state. you won't loose anything but in case of jenkins, you loose data. 
in case of data say mysql, if you want to create a multiple instance of mysql, you can't do it.
database if you want to use it, do "write once, use one."
you can have read replicas.
one primary and other are going to be readreplicas.
How can you create this kind of architecture. 
- you have to maintain the state. 
thats why, k8s came up with concept for database pod. 
they came up with idea stateful sets.
- how it is maintaining?
as usual, how are you going to create deployment?

read replicas going to be sync with primary pod automatically.
rds mysql cluster
kind: StatefulSet
https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/
https://bmc.com/blogs/kuberneste-postgresql

static IPaddress
application loadbalancer
create ipaddress and attach it.
type: loadbalancer (application load balancer)
service:
route: pathbased routing
url/admin
url/user
in k8s - assign certificate, dns
ingress object,
how to use it?
https://kubernetes.io/docs/concepts/services-networking/ingress/
package managers
----------------
file will be extrated and stored in a relevent location.
pip
gem
yum
apt
npm
rpm
dpkg
get file from repo, extract and distribute among different directories.
kubernetes
helm 
 packager manager
package
yml
 - dev
 - test
 - prod
helm packages
$ helm install
$ helm get -h
https://helm.sh/docs/intro/using_helm/
install helm on your client side
- install nginx
$ helm install nginx
look for syntax for directory structure.
------------------------
tomorrow
- ansible/terraform





Monday, February 7, 2022

Day7 - k8s RC, RS, Deployment, Taint tolerance ..

2/07/2022 - Class Notes

ReCap from last class

- k8s
  - Architecture
  - Master node
  - Worker Node
  - Client (Your PC)

  - Configure Master, Worker, Client
  - kubectl 
    - using ad-hoc command
    - using yaml file

  - run command
  - expose command

yaml files
- pod.yaml
- service.yaml
- nginx.yml

yaml file contenet
apiVersion:
Kind
Metadata
spec:


pod has pod definition
service file has service definition

Go ahead and start aws instance or your VM.
$ ssh -i rsa_user user@ip

# kubectl get node
Master -> control-plane, master

# kubectl get pod

# kubectl get svc
  exposing service

# kc get svc nsserv -o yaml
# kc get pod ns -0 yaml



a service is a ogical set of pods and acts as a gateway, allowing ..

- we need multiple pods. How can we service multiple pods? how many ways we can create pods?

We are going to use replication set, replica-set or deployment.

service can decide how to manage pods. 

search for workload resources: 

https://kubernetes.io/docs/concepts/workloads/

Replication controller
a replicationcontroller rnsures that a specified number of pod replicas are running at any one itme. in other works, a replicationcontroller 


search for pod 
-> look for pod definition.

Search for replication controller

eg,

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:  # replication control spec
  replicas: 3
  selector: 
    name: nginx
  template: # pod definition
    metadata:
      name: nginx
      labels:
        app: nginx
    spec: # pod definition
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Would they be running on same node or on different?

schedular will decide on what node to create?

# vi rc.yml
# kc delete pod n1
# kc delete svc n1serviec
# kc get svc

# kc apply -f rc.yaml

# kc get -f rc.yml
you see desire, current, and ready
# kc get rc
# kc get pod

under name section, you see name attach..

RC is tightly coupled here. job is going to run at particular node only. if node is not available, job is on the queue.
multiple node with label?

instead if selector, for multiple label, we will use replica set.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx
spec:
  # modify replicas according to your case
  replicas: 3
  selector:
    matchLabels:
      app: nginx 
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
        env: dev
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
# vi rs.yml

# kc apply -f rs.yml

# kc get pod

# kc delete -f rc.yml

# kc get rs
# kc get rs -o yaml # yaml file output

# kc get rs (replica set)
# kc describe rs 

# kc get pod
# kc delete pod nginx-abdfd
# kc get pod

# same number of pods.
cluster will always maintain 3 replicas all the time.


if you want to update,
just change the image: nginx:latest

# kc apply -f rs.yml

# kc get pod

# kc get pod nginx-dfssd -o yaml

look at the image version of the output.
spec"
 containers:
 - image: nginx:version

# kc get pod

# kc delete -f rs.yaml
# kc apply -f rs.yml

updating is a problem with replica set. All of the pods will be updated. your system may be down. couple of sec/minutes of downtime.

There is another method called 'deployment' All three options are good but 

lets say you want to update canery or blue greeen , or percent wise update. that time, you want to update on control rate rather then one time. 

you can use 'deployment'

only different is that you will be using object on deployment.

$ cat dep.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3 # rollout
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

# kc delete -f rs.yml

# kc get pods
nothing is there

# vi deploy.yml
paste the content above.

# kc apply -f deploy.yml

deployment is created.

# kc get deployments

# kc rollout status deployment/nginx-deployment

# kc get deployments

# kc get rs  # replica set, it will show there as well.

modify

# kc get pod
there pods are running


# kc set image deployment.v1.spps/nginx-deployment nginx=nginx:1.16.1

# kc edit deployment/nginx-deployment

image: 1.16.1 # change the versio under spec: containers:

its modified automatically

# kc get pod

kc rolllout status deployment/nginx-dployment

you will see message -  old replicas are on pending termination 


# kc get rs
update is graceful shutdown. when deployment is running, it will wait until all job on the pod is completed.

so, we see we will use deployment to update your product.

search for service on k8s documentation.


apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

# cat deploy.yaml

# kc get expose --help

you can use possible resource.

we have 
selector:
  app: myapp


expose outside
$ cat svc.yaml

spec:
  type: NodePort

# kc apply -f svc.yaml
# kc get svc



Dashboard
Simple example

How to create a dash board and deploy a micro service.

google for k8s dashboard

$ cat dashboard.yml 

ServiceAccount - object
apiVersion: Namespace
metadata:
  name: kubernetes-dashboard

what is role?
- its a permission, priviledge.
it contens roles, resources.

user define rules

cluster level roles
- clusterrole
and we bind with user.

assign permision based on the role to the user.

role binding - service account 
 - service account is just like a user. it is binded with certain roles, clusterRolebinding, role binding.

# kc apply -f recommended.yaml

# kc get pod -n kubernetes-dashboard

# kc get svc -n kubernetes-dashboard

how to modify?
download and apply or use the edit command

# kc edit svc -n kubernetes-svc kubernetes-dashboard 

Change from clusterip to NodePort

# kc get svc -n kubernetes-dashboard

you see type and ports different now..

port: 31687

get the ip of your node and use ip to access
https://ip:port

option
- token
- kubeconfig

how to get token

follow the guide create an authentication roken (rbac)
https://github.com/kubernetes/dashboard


create clusterrole binding

# vi user.yml

add service bindng

# kc -f user.yml 

# kc -n kubernetes-dashboard get secret $(kubectl - kubernetes-dashboard get sa/admin-user -o jsonoath="{.secrets[0].name}) =o go-template='{{.data.token | base64decode}}"

# kc -n kubentes-dashboard get sa/admin-user
# kc -n kubernetes-dashboard get sa/admin-user -o yaml

# kc -n kubernetes-dashbard get secret admin-user-token-mbkg8 -o yaml

# vi token
# cat token | base64decode

copy the =token and go to dash board and paste under token section 

now, you have access to dashboard.

where the pods are deployed?
# kc get pod
# kc describe pod <pod-name>

you will see under events what node deployed to.

or you can go to dashboard
go to default dashboard
go to pods and you will find it.


how do I deploy windows app (.net app?)?

or a linux server with 16gb of ram.

you want to select the node rather then randomly selecting it. You want to select your node based on your requirement.

- We will use nodeDelector option.

how to declare nodeSelector?
go to k8s web page and serch nodeselector

assigning pods to Nodes.


nodelecector:
  disktype: ssd

# kc get node

how to know what node to select?
use selector, level

# kc describe node <node-name> 

you will see namespace, allocated repsources, system resources, capacities.
look for labels

you have to specify values based on key-> value paid.

nodeSelector

multiple filter, 
afinity/anti-affinity

provides multiple options.


To select the pod, you can use these three options,
- nodeSelector
- Node affinity
- node anti-affinity

There is another option
Taint and tolerations

taint -> 
tolerations ->

k8s.io  - search for taints

search for taints and tolerations

# kc taint nodes node1 key1=value1:Noschedule

read about taint and toleration

======================
tomorrow,
configmap
pv
pvc
storageclass
ingress
statefulset
jobs

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

Today, we created
- pod, svc, rc, rs, deployment
- dashboard, tocken
- Controlling purpose -> NodeSelector, affinity, taint, toleration

# kc taint ...
# kc describe 

Thursday, February 3, 2022

Day 6 - Kubernetes in depth

2/03/2022 - class note
Docker, Docker compose
Recap
Orchestration Frame
Clusters
Swarm
K8s
Master 
Nodes (pool of worker nodes)

Master node
API server
Controller Manager
Scheduler
ETCD
kubeadm
Worker Node
- kubectl
- Kube-proxy
- PODs

How to configure k8s using kubeadm?
- Create 2 VMs per cluster
- 1 VM -> client (it can be your PC/Laptop)
How to configure?
- Login to AWS console
- Select your region
- You need elastic IP
- Go to instances to see if you have existing instinaces
- Go to services -> EC2
- Select ubuntu t2.micro (two instances) if you want to load jenkins or other program, use medium.
go to kubernetes.io and search for kubeadm
- look to installation
- look for requirement, you need to use t2.medium. 2GB, 2CPU
- add storage, security group. ssh enable
your 2 instances are ready. Create other 2 as follow
k8s-master - t2 medium
k8s-node01 - t2.micro
k8s-node02  - t2.micro
k8s-client (Treat this like a client pc, jump host, bastion host)
Login to each instances node01, node02, master, and client
Now, we have to install required utility on master and nodes.
follow this guide,
https://github.com/qfitsolutions/k8s/blob/master/k8s-master
CNI - container network interface.
@master, and both node, run the following command,
apt-get update && apt-get install -y apt-transport-https && \
apt install docker.io -y && \
     systemctl start docker && \
     systemctl enable docker && \
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF && \
apt-get update && \
apt-get install -y kubelet kubeadm kubectl kubernetes-cni

Enable cgroup driver, otherwise kubelet will not start. Run it on node side and restart the docker.
cat <<EOF >/etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl restart docker
systemctl status docker

# kubeadm
you will see the output
available commands
look at init option, k8s control plan,
join - to join existing cluster
token - manage token..

Now, you have to initialize
kubeadm init --ignore-preflight-errors all   
or
sudo kubeadm init --control-plane-endpoint "PUBLIC_IP:PORT" --ignore-preflight-errors all 
Review all the output.
Your control node is initialize successfully.
You can join any number of worker node. Copy the join command and execute on worker nodes.
Static pod - kubelet is going to be managed, api server, etcd, kube systems.. kube-proxy
You have to config kube config by running the command below,

mkdir -p $HOME/.kube && \
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config && \
sudo chown $(id -u):$(id -g) $HOME/.kube/config
cat .kube/config 
you will see very important info
server: https:ip:port
https://ip:6443
if IP is public, you can reach from anywhere.
kubectl is a client command.
# kubectl get node
check status: NotReady
Role: control plane.
---------------------------------
You also have to deploy pod network.
go to kubernetes.io installation page and see add-on, networking and network policy
There are lots of policy
- calico 
- Flannel 
- Weave net - We will use it. click on the link 
  it cana be installed on CNI-enabled k8s cluster. we used this option so we should be able to use it
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
- service account created
- authorization, role binding
- daemonset - going to run background process such as agent. like kubelet, 
now run kubectl command
# kubectl get node 
you will see status: ready
# kubectl get pod
what is pod?
- it's a container. 
k8s devide memory into multiple namespace. namespace holds logically spliting memory. 
# kubectl get pod --all-namespaces
coredns
etcd-ip
kube-apiserver-ip
kube-controller-manager-ip
kube-proxy-2

Now, lets go to node systems and run the join command.
#Note: get kubeadm join command from k8s master and execute like below command:
#kubeadm join 172.31.26.24:6443 --token hpnfgz.52pq3e95hrsz68c6 --discovery-token-ca-cert-hash sha256:92f783e806fb2b0bd36c2847d276847e78a14e07f86256cdbb4f3d79b9618df8

read the output carefully
you will see message that node has join th cluster
go to master node and run
# kubectl get node
Now, go to 2nd worker node and execute the join command. once done, go to master node and run
# kubectl get node
you will see one master and 2 nodes.
see under Roles.
# cat .kube/config 
copy the config file output and paste under home dir on client node.
apt-get update && apt-get install -y apt-transport-https && \
apt install docker.io -y && \
     systemctl start docker && \
     systemctl enable docker && \
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF && \
apt-get update && \
apt-get install -y kubectl kubernetes-cni
cat <<EOF >/etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl restart docker
systemctl status docker

# mkdir .kube
$ vi ./kube/config

k8s-client -> k8s-Master -> k8s-node01|k8s-node02]
PC/Laptop -> k8s-Master -> k8s-node01|k8s-node02]
google
"aws kubeconfig update"
aws eks update-kubeconfig --name example (cluster name)

goto your pc, under home, crete .kube/config 
and paste the content
# kc get node
you should get output. If it hangs, go to congig and get the public IP and paste on server line..
try again
$ kc get node
invalid certificate
cert is generated backed on IP so you may get cert error. If everything is good, result is good.

Can we have multiple master nodes in k8s?
- yes, but you can have multiple components on different nodes. spilit the componenet
- create high availabliity cluster with kubeadm
- high availibity etcd and so on..
next, how to deploy application on k8s
break time...
We want to deploy pod
to start pod, 
kubectl run command
kubectl -> kc
kubectl run
kc expose
# kubectl
you will see detail help output
look under basic commands
create -
expose -
run - 
set - 
Lets look at these two commands: expose and run
expose - take a replication controller, service, deployment or pod and expose it as a new k8s service
run - run a particular image on the cluster

# kc run --help
see th eusage..
review the output, go through the exaples.
# kubectl run n1 --image=nginx:latest --port=80
podname=n1
image=ngins
port-> 80
# kc get pods
Status: containerCreating
===================================
Q. Can we host private registry on our on-prem env?
go to hub.docker.com
search for "registry". just use it.
===================================
# kc describe n1
How can you access. lets say pod is deployed to node02.

# kubectl expose --help
read the help output

# kubectl expose pod n1  --port=80 --target-port=80 --name=n1service --type=NodePort
--port=80 is your nginx port
target-port=80 is service port
n1service - is the name of service we just gave.
What is service?
a service represents a logincal set of pods and acts as a gateway, allowing (cielnt) pods to send requests to the service without needing to keep track of which physical pods actially make up the service. so basically now servie will redirect the consumer to the actual working pod.

service types,
cluster-ip ->  cluster level
NodePort - node level
Loadbalancer - use external (public) IP, you can use it.
# kubectl get svc
# kc describe svc n1service
Type: NodePort
selector: run=n1
clusterip -> private ip, such as database, use local ip
Nodeport - web site -> you use public ip, so you can use nodeport is going to be used. node port is like bridge port. it enable the port forwarding.
LB - You can use loadbalance for public IP.

google for "static ip in service gke"
get the node IP and use at the browser, you will be able to access the nginx default page.
http://ip:32703

Kubernetes dashboard,
github.com/kubernetes/dashboard
kc describe svc n1service

rather than running commands, we can convert command line option to yaml file.
$ mkdir feb22
open it on vs code
FEB22
 - k8s-example
    pod.yml
kc describe svc n1service
kubectl expose pod n1  --port=80 --target-port=80 --name=n1service --type=NodePort

lets convert these two cmmmands into yaml
what we need is
apiVersion: v1
kind: Pod # what we want, pod
metadata:
  name: n1
  labels:
    app: n1
    env: dev
  namespace: dev
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80

---
apiVersion: v1
kind: Service # what we want, service
metadata:
  name: n1service
  labels:
    app: n1
    env: dev
  namespace: dev
spec:
  Type: NodePort
  selector:
    app: n1
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80




@k8s.io site, search for service.

# kc get ns
you see default namespace.
You want your own.
# kc create ns dev
dev namespace is created.
# kc delete ns dev
you can create namespace using yaml file.
google for namespace and how to create it.

---
apiVersion: v1
kind: Namespace
metadata:
  name: dev
 
* - means list.
$ vi nginx.yaml
#kubectl run n1 --image=nginx:latest --port=80
#kubectl expose pod n1 --port=80 --target-port=80 --name=n1service --type=NodePort
apiVersion: v1
kind: Namespace
metadata:
 name: dev
---
apiVersion: v1
kind: Pod
metadata:
 name: n1
 labels:
   app: n1
   env: dev
 namespace: dev
spec:
 containers:
 - name: nginx
   image: nginx:latest
   ports:
   - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
 name: n1service
 labels:
   app: n1
   env: dev
 namespace: dev
spec:
 type: NodePort
 selector:
   app: n1
 ports:
   - protocol: TCP
     port: 80
     targetPort: 80

# kc apply -f nginx.yaml
# kc get pod -n dev
next week helm 
read yaml file, write yaml file.
https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
k8s
terraform
ansible


---------------------------------

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ais-ifm
  labels:[InternetShortcut]
URL=https://codeshare.io/WdlgYy

    app: nice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ais
      tier: web
  template:
    metadata:
      labels:
        app: ais
        tier: web
    spec:
      containers:
      - name: tomcat
        image: tomcat:latest
        ports:
        - containerPort: 8080
        resources:
          limits:  
            cpu: 1000m
            memory: 600Mi             
          requests: 
            cpu: 500m
            memory: 300Mi
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        resources:
          limits:  
            cpu: 400m
            memory: 200Mi             
          requests: 
            cpu: 200m
            memory: 100Mi
            
            
            
---


apiVersion: v1
kind: Service
metadata:
  name: ais-service
  labels:
    app: ais
spec:
  ports:
   - name: tomcat
     port: 8080
     targetPort: 8080
   - name: nginx
     port: 80
     targetPort: 80
  type: NodePort
  selector:
    app: ais
    tier: web
    

Wednesday, February 2, 2022

Day5 - Docker, swarm, k8s intro

 2/02/2022 - class notes

docker, service, network - overlay, 
Recap from yesterday
If you running muclitple containers, how do you connect them?
https://github.com/fgitsolutions/docker
$ cat docker-compose.yml
version: '3'
services:
  web:
    build: .
    ports:
     - "5000:5000"
  redis:
    image: "redis:alpine"

- Discussed about Dockerfile
- Docker-compose
  - multiple containers
- Single host/standalone host
- If you run multiple containers, you will be out of memory
- Distribute the containers among nodes
We need custer managerd by
 - manager
 - Worker nodes
Who is going to provide this kind of facilities
 - Docker SWARM
 - K8s
 - Mesos
Swarm architecture
docker swarm init
docker swarm join
google and see the swarm internal atchitecture.
- internally swarm manager has multiple components.
 - API -> accepts commands and creates service object
 - Orchestrator
 - Allocater
 - Dispatcher
 - Schedular
Worker Node
 - worker 
 - executor
LAB
Login to your VM
# ssh swarm-manager
$ docker nodes ls
$ docker swarm init  # initialize
 initialized current node is now manager.
you are manager.
@worker node
$ ssh swarm-worker
$ sudo -i
$ docker swarm join <key> ip:2377
Go back to master and run
$ docker node ls
manager is a leader and other is a worker node.
You can execute your program
Docker Service => docker run
Docker stack -> docker-compose
you can execute as a job or a service.
# docker service
read the output
$ docker service create --help
# docker service create --name=n1 -p 80:80 nginx
name -> n1
-p -> port
image-> nginx
List it now,
# docker service ls
# docker service ps n1
scale
# docker service scale n1=3
it created 3 replicas. 
# docker service ps n1
Your service will load balance.
# docker inspect <ID>
it is going to use overlay network
# docker network ls
see the ID and the driver type.
It will creates tunnel between all the nodes
VPC or VNET pairing?
- able to communicate between one network to another. Establish the communication between private network.
# docker inspect ingress
look at under peers, you will see two IPs.
peer mean they both can communicate. its like creating tunnel between these two node. 
manager/node can transmit the communication.
google "vpc peering"
google for "overlay network"

# docker swarm --helo
# docker swarm join-token
# docker swarm join-token manager
# docker swarm join-token worker
# docker service ls
# docker serviec ps n1
how to run muitple cotainer 
# cat docker/docker-compose.yml # refer the example from yesterday


$ cat swarm-compose.yml
version: '3'
services:
  web:
    build: .
    ports:
     - "5000:5000"
  redis:
    image: "redis:alpine"

# docker git pull
# docker service 
review help
# docker service rm n1
# docker stack services mystack
# docker stackk
# docker stack rm mystack
if you want to deploy
our instance is t2.large
# cat ci.yaml
it will create multiple containers

# docker stack deploy -c stack-ci.yml costack
stack is multiple 
List all services from stack-ci
# docker stack services cistack
# docker stack services cistack
if you keep creating, we may go out of resources.
# docker logs <id>
# docker stack service cistack
# docker ps -a

# docker stack deploy -c stack-ci.yaml cistack
Remove
# docker stack rm cistack
# docker stack services cistack
everything is gone.
# docker stack service cistack
# docker logs <docker_Id>
getting error for dogs
# docker stack rm cistack
# docker stack deploy -c stack-dc.yml mystack
# docker stack services or ls
# docker stack services mystack


version: '3'
services:
  web:
    image: 'devopsjuly22017/web:latest
..

# vi stack-dc.yaml
# docker stack deply -c stack-dc.yml mystack
# docker stack service mystack
docker is not production ready by itself. because of the nature. 
docker swarm does not have features that k8s offers.
k8s is production ready. Swarm can be used in production but it does not have alots of features that k8s offers.

Read about "ECS cluster in AWS" - aws implemented docker cotainer (microservice service) implmentation.
go to aws
search for ecs
-> get started

k8s ->
google and read about k8s features.
will discuss 'architecture and internal components;
google k8s architecture
----------------------------------------------------
user (cli) -> api -> k8s master -> Node1|node2|node3|..|Noden  --> Image Registry

you are going to use,
k8s-client
k8s-master
k8s-nodes
k8s features
- open source systems for automatiing deploying ....
- Automated rollouts and rollbacks - you created 3 replicas, version is 1.1 and need to update 1.2. How do  you do it? but k8s will do roll back/rollup. one by one update/one by one update. high availibity. if something goes bad, if will roll back. 
- storage orchestration - automatically mounts storage system of your choice such as aws, gcp or nfs, iscsi, gluster, ceph, cinder or flocker
- automatic bin packing
- service discovery and load balancing
- secret and configuration management.
- horizontal scaling [ up and down your app]
- Batch execution - run jobs
- IPv4/IPv6 dual-stack
- Self healing - restart if fails.
Node level and container level.
Deployment types
- blue green 



Kubernets components
--------------------
Control plane
kube-apiserver
- api server the component of the k8s control plac=e that executes the k8s API. The API server is the front end for the k8s control plane. its like a front desk
- ETCD - database storage (NoSQL database). key value backing store for all cluster data. maintains the state of your cluster. what is connected, 
- kube-Scheduler -> when request comes to say create container, checks which node is free, which node is capable to create the conteiner.  load balances. 
kube-controller-manger (internal component)
  - control takes a decision, logically each controller is a separate process 
some types of controllers
- node conteoller - checks to see if nodes go down. checks health of nodes.
- job controller - watches for job objects. self healing, creates pods to run jobs.
- end poing controller
- service account and token controllers

@aws, create auto scaling group

cloud controller-manager
- this can use use with cloud service providers.
- cloud specific controller logic.
node controller
route controller
- service controller
5 components
- API server

Node components
on node side,
1. kubelet
- an agent runs on each node in the cluster. makes sure that containers are running in a pod.
kubelet does not manage containers which were not created by kubernetes.
2. kube-proxy
- kube-proxy is a network proxy that runs on each node in your cluster, implementing part of the k8s server concept.
- it maintains network rules on nodes. These network rules allow network counication to your pods from network sessions inside or outside of your cluster.
- it uses the operating system packet filtering layer if there is one and its available, otherwise kube proxy forwards the traffic itself.
3. Container runtime
- container runtime is the software that is responsible for running containers.
- k8s supports containerd, cri-o, docker, rkt and other implementations. 

apart from these components, we have addons
- DNS
- WebUI (dash board)
- Container repsirce monitoring
- Cluster level logging

There are 
- Opensource
- Enterprise :- ~PAAS
k8s setup
google, kubernetes set up

create minimum 2 server
1. install kubeadm, kubelet and kubectl
2. Initialize run commands kueadm init <args> - initialize master and provides the join command.
we are going to use two types of commands
1. client command - kubectl
2. Admin : kubeadm (master)

github.com/qfiitsolutions/k8s
https://github.com/qfitsolutions/k8s
know little about openshift service as well.
https://docs.google.com/document/d/1_ZQ8XN1dfcaXkBJHPMIlZqoW4_BePbrCU_LW3yvDTAs/edit

cluster contains
- master
- nodes
Tomorrow's topic
- set up k8s
- PODS
= Write yml
- Dashboard
- Deployment
- Service



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

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ais-ifm
  labels:
    app: nice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ais
      tier: web
  template:
    metadata:
      labels:
        app: ais
        tier: web
    spec:
      containers:
      - name: tomcat
        image: tomcat:latest
        ports:
        - containerPort: 8080
        resources:
          limits:  
            cpu: 1000m
            memory: 600Mi             
          requests: 
            cpu: 500m
            memory: 300Mi
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        resources:
          limits:  
            cpu: 400m
            memory: 200Mi             
          requests: 
            cpu: 200m
            memory: 100Mi

Tuesday, February 1, 2022

Day4 - Docker , docker swamp, docker compose

Day4 - Docker  - class notes
Docker Network
  - Bridge
  - Host
  - None ->
Volumes
  - Mountpoints
  - Persistent data
How to run docker
  - as a job
  - As a service
Ports
  -p
  -P
Image -> From running containers
Push -> Registry
Docker Hun
ECR
Quay
Jfrog artifactory
Nexus repo
Image creation
Image: docker commit containerID
Developer code/release/microservices
  - Avoid manual process
SHould be able to perform
  - pull
  - Run
  - copy
  - configure
  - save (commit)
We want to avoid these above step perform not manually but automatically. How can we do it?
- By using image build as a code concept. 
We use Dockerfile and specify all the stuffs there.
Dockerfile is going to help us to build the image. We will specify the base image, specify the packages needed. what files you need to cpoy, what ports, what env, what packages you want to download, what script do you want to execute.
Docker file contents,
  - Image
  - packages
  - copy, download, copy files, certificates
  - expose (ports such as 8080, 5000)
  - Env
  - initscript
Dockerfile
FROM ubuntu # what image do you want to specify, here we specify ubuntu, so it will download ubuntu image
RUN apt install default-jdk* -y # install jdk packages
ADD . /app   # copy everything from current directory to /app on the container
WORKDIR /app  # /app is going to be home directory for the user login.
EXPOSE 8080  # exposting the port 8080
CMD [java -jar abc.jar]  # start a service, when system boots up, service starts automatically. Run initial command. (You can call it as a boot strap script)
so the dockerfile content is as floows
# cat Dockerfile
FROM ubuntu
RUN apt install docker-jdk* -y
ADD . /app
WORKDIR /app
EXPOSE 8080
CMD [java -jar abc.jar]
$ docker build -t web . # [ docker build -t (tag)
when building the image, it will install ubuntu and at the build time, it will install something (jdk in our case) at the time of build. Run command helps
cmd command runs the java -jar abc.jar.
-----------------------
LAB
# start your VM, and login to the VM.
github.com/qfitsolutions/docker/


FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py]


git clone github.com/qfitsolutions/docker.git
FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
========================
open new session and monitor
# docker ps -a  # watch, 
===========================
# docker --help
# docker build --help
-t - tag
-f - name of the file path
# docker build -t web:latest .
. means it will refer the dockerfile from the current directory.
observe the output. 
dockerfile is analyzed and proceed...
it performs 5 steps,
- it is pulling the image
- added the content. /code
- running in
- removing intermediate container (docker build command when downloaded the image, starts a container, add content, and it removes it self,
it starts a new instance and starts next step -> app.py
installing packages, removing .. just look at the output. 
# docker ps -a # command shows the imtemediate container. keep running
Run the commands inside requirements.txt 
# cat requirements.txt
flask
redis

Review this file,
https://spring.io/guides/gs/spring-boot-docker/
# cat Dockerfile
FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Google,
Entry-point docker example
# cat Dockerfile
FROM ubuntu-trusty
CMD ping localhost
if you build this image, it will give you ping output
# docker run -t demo 
# docker run demo hostname
# docker run --entrypoint hostname demo
here hostname was run in place of ping command. It is not executing ping command but hostname is overwriting the default command.
so default entry poing is replaced.
$ docker run --entrypoing hostname demo
overwride the default cmd command.

# docker run -d demo
# docker ps -l
# docker exec 

FROM ubuntu:trusty
cmd can overwide default behaviour.

CMD you can override, on ENTRYPOINT, you can't overwride.
Google for
Dockerfile example
https://docs.docker.com/get-started/02_our_app/
https://docs.docker.com/samples/dotnetcore/
There are multiple repositories, modules available.
When you have multiple micro services, you have single application, you have multiple microservices, how do you start whole environment. 
Even, on dev, Test,Prod env?
Microservices
- Build all images


Google microservice architecture
https://microservices.io/
https://microservices.io/i/Microservice_Architecture.png
on the image above, there are 7 microservies.
4 micro-services have 3 dbs, different images.
Here, we are going to run Docker run command.
we have to run 'Docker run' command multiple time.
we will define image, run docker run multiple time and variable img
such as 
Array:[img1 img2 img3]
For loop:
  Docker run $img
but the problem is say we will us port, network, volume, name or more.
Some case some option may needed and some may not needed.
it becomes complecate.
rather than that, we use yaml code.
we will specify dynamic input
for eg,
nexus
 img
 port
Jenkins:
 img
 port
 Volume
 network
Maven:
 img

So, what is yaml file?
its like an xml file. 
xml, json, yml -> these all keep data. carry data.
we have Map and list
in yaml, we us map and list
kep pair
Map:
  Key: value
  course: devops
  City: DC
List # multiple values, not only key pair, muitiple values
  Cities:
   - DC
   - NY
   - LA
Fruits:
  Banana
  Apple
  Orange

List, specify multiple values...
services:
  jenkins
  nexus
  maven
  spring

services:
  jenkins:
    img: jenkins
    port: 8080
    network: mynw
  nexus:
    img: nexus
    Port: 8081
  maven:
    img: maven
  spring:
    img: mysprint
    Port: 8443
Docker will read it.
We will use docker-compose can read this yml file. 
docker-compose -f abc.yml/docker-compose.yml up
 
to start multiple containers
$ docker-compose -f abc.yml/docker-compose.yml up
 
How can we execute?
login to your system 
# cat docker-compose.yml
version: '3'
services:
  web: # web application, which we name as 'web'
    build: . # build a new image, 
    ports:
     - "5000:5000"
  redis: # backend application, pulls the image and builds
    image: "redis.alpine"
# docker-compose
no command found
apt install docker-compose
we need to install it. 
# apt install docker-compose -y
# docker-compose
you will see options
you see, start/stop, rm, run, build and much more options
# docker compose -f docker-compose.yaml up -d
up is sub command
-d -> run in background, deatach mode.
it will successfully builds first and after 2nd service.
two containers at a time.
# docker-compose ps
rather than docker run, use docker-compose command.

ip:port
if page is not displayed, 
go to instance, security group and add 5000 port - anywhere.
and refresh the page, you should be able to see the page.
======================================
try this one too and see what happens.
# docker run -itd --name web --image redis:alpine -p 5000:5000
docker is used to run single container at a time where as docker-conpose is sued to run multiple containers at a time.

- docker swarm
- Kubernetes
- Mesos
- tanzu
docker swarm is implemented by docker while k8s is by kubernetes by google.
google docker swarm atchitecture.
- internal distributed state sotres
- Manager manager manager
worker worker worker worker worker
its very simple to bring it into 
there are few commands
# docker
look at under management commands.
# lets make current machine as a maanger
# docker swarm
read the output help content.
# docker swarm COMMAND --help
# docker swarm init
it initilizes.
current node is a manager.
to join other nodes.
$docker swarn join --token <token id> 192.168.10.20:2377
Create a new aws instance as swarm-worker node
use t2 large to create new instance.
install docker command
$ apt update
$ apt install docker.io
run the join 
$ docker swarm joing --token <tokern no> 192.168.10.20:2377
you may get error, 
add inbound rule and add port all traffic / all traffic
now should be able to work without issue. if you get error, keep adding the error based on the error or take the corrective actions.
# docker swarm leave
# rejoin using the above command - docker swarm join...
# cd docker
# vi docker-compose.yaml
web:
  image: "devopsjuly22017/web:latest"
  ports:
   - "5000-5000"

# docker stack
# docker stack deploy -c docker-compose.yml mystack



# docker node ls
read about k8s at kubernetes.io

service
x

Maven, Jenkins - Class Notes

 Maven - Class Notes
----
apt install tree
Build configuration tool - Maven
Project directour structure
Build process (pom.xml)
Life cycle phases
  - validate
  - compile
  - Test
  - Package
  - Install
  - Deploy
command
$ mvn -f pom.xml clean install/deploy
install vs deploy
nexus/jfrog

draio - mac drawing tool
diagrams.net

maven -> jenkins -> nexus repo
webhook (jenkins)

--------------------
Building lab environment
- login to aws console
hostname: maven-host
- connect 
$ ssh -i "user.pem" ubuntu@ec2-192.168.10.20.us-webt-1.compute.amazonaws.com
security -> 
inbound rule
ssh -> use your ip
ssh anywhere 0.0.0.0
or ssh source anywhere -> specify your ip

$ tree ../core-app
$ mvn clean
going to delete target directory
when you run mvn compile/package
the output, packaged file will be on target directory
$ cd core-app; ls
$ mvn ..
it generates target file 
$ mvn clean install
deletes all old target directory contents and re-creates
it compiles, packages and stores on repo as well


multi module projct
$ cd maven-multimules
$ tree simple-parent
 -src
   - main
   - test
$ git remove -v
$ cat pom.xml
distribution manage task, we are going to manage
push to remove site using vscode
$ git status
$ touch .gitignore
$ vi .gitignore
target/
$ git status
$ rm -rf .gitignore
$ mvn clean
$ git pull
$ mvn clean install
$ git status
Notice: git will ignore the target file.

We have to login to
- ssh: ec2
- git we use, clone/pull operation
- we use Maven
developer modify the file everyday.
so you have to manually upload/download
so, we use process continue integration tool (jenkins) to automate the task.
We are going to install jenkins tool.
continous integration tool
- jenkins
- gitlab runner
- circleci
- azure devops pipeline
- bitbucket pipeline
- gitub actions
- code pipeline
- travis
- teamcity
=========================
4 steps
Step 1. maven commands
Step 2. jenkins
Step 3. 
Step 4. 

You can install maven and jenkins on the same system but its better to use different instance.
1. Launch a new instance - use t2.small for jenkins
2. t2.micro for maven 
login to the hosts:
Install jenkins
use online instruction
set up repo or download the package and install - either way..
$ sudo apt-key add - 
$ wget -q -o - https://pkg .. > /etc/apt/sources.list.d/jenkins.list'

$ apt-update
$ apt install jenkins
$ apt repolist (apt ubunto repolist)
failed to start LSB: start jenkins at boot time..
read the error message..
no jave executable found in current path

Install JAVA
look at the bottom of the page, you will see guide how to install.
$ install openjdk-11-
$ systemctl start jenkins
$ systemctl status jenkins

get jenkins public ip and paste on browser
http://<ip>:8080
you may not get any page, so you have to add 
click on the instance
- security  and add port 8080 anywhere and save the rule
refresh on the browser, you will see it.
follow the instruction to set up user
jenkins home directory
$ cd /var/lib/jenkins
you finally completed jenkins server.

click on the create a job from the middle of the page
item name: test job
select Freestyle projecct -> basic type 
click ok
you are on general
select discard old builds
source code management
git
build
add exxecute shell
echo "Hello world"
click ok
we created a simple job.
click o build now, 
click on build history
- click on console output - you will see the output
- go to command prompt and run $ echo "hello, World" and compare the output.
as of now, we created new item, free stye project. selected couple option with echo command.



$ git remote -v
get the url
now go to source management and paste the git url
brnach /master
save it and build now.
it will perform the job.
job is executed. 


to to home page
manage jenkins
- manage plug-ins

# cd /var/lib/jenkins
# cd workspace/testjob
# ls
src
pom.xml
where do you define the linux credentials?
- we install jenkins on the linux server so it use the system account to launch the job.

click on manage plugins
search "maven
select maven integration
go to home dir
- click on new item
Now, you can see maven project
name: core-app-maven-build
select maven project
clcik ok
copy your repo 
specify git
go down
build option , it automatically understands
Root pom
pom.xml
Under goal and option
clean install
save the job
you save new job
to go home, amd click on manage jenkins
- configure tools, global tools configuration
click on add maven
name: maven-3.8.4   # specify the path
select Install automatically
jenkins automatically downloads maven pacakge and installs it.
you can select the version you want..
once saved, click on build now.
click on the job and console output
where can we put maven server details if we jenkins and maven are on different server..


As of now, we install jenkins and created job. and successfully executed the job
check git link for 1:05:00 - 1:07:50
$ mvn archetype...
$ tree core-app
github.com/devopsgsvc

add multiple people into the team and distribut the job.
that way, you can add number of executors
- click on manage jenkins
- Manage nodes
to add plugins
- add, remove disable enable plugins..
- you can add n numbers of hosts.
- click on new node
or
configure clouds
node name: node01
select permanent agent
description: testing
number of executor: 3
remote root directory: 
paste from the command below
go to command line and create dir
$ mkdir jenkins-agent
$ pwd
copy the path

Labels: maven-label
Usage: use this node as much as possible
launch method: launch agents via ssh
Host: IP address - if cloud, use provate IP
credentials: 

Host key verification strategy: known hosts file verification strategy
to login from node1 to node2, we can use password or key.
Node 1 ---ssh---> Node2
$ ssh node2
you can use id_rsa.pub per user basic or
if you are using cloud, you can use authorized key from user's home directory to .ssh.
This public key can also be used to login to remote machine for passwordless login.
add credential
domain: global credential
kind: ssh usernane with private key
id: ubuntu
private key:
key:
paste the output of your authorized_keys value.

Host key verification strategy:
save
click on node01 and click on log
you will get the status if it is succesfully connected.

why labels
if you want to add multiple node, each node may be doing different tasks, say 2 node maven, 2 docker, or other job, so label will help you to pick up..
jobs -> configuration
restrict where this project can be run 
  label expression: maven-label
specify your label here.
once done, click on build now.
click on job# and click on console output.

click on workspace - delete
or go to command line and browse to the jenkins location.

go to home
- manage jenkins
- configure clouds
error - no cloud implementation for dynamically allocated agents installed .. go to plugin manager...

Do some research on,
how to configure cloud concepts on jenkins... 
configure -> fill required info, 
Will cover this instance tomorrow..
- dynamic node
- Webhook
- Authentication
- Pipeline
- Nexus
- Docker
If you are using cloud service, make sure to stop/delete.

draw.io

Day2 - Jenkins

Jenkins - review - Class Notes

Lab: Create a jenkins server
- Create job
- execute job
- Check log
- Create a node and add to the server
- Webhooks

Install http server java
https://stackoverflow.com/questions/3732109/simple-http-server-in-java-using-only-java-se-api

=======================
Recap
- Maven
- Job
- Jenkins
  - Jekins jobs
    - Config )restrict this project can run
    - URL 
    - Where job is executed
    - Added new agent (node01)
    - Manage jenkins (manage nodes and clouds)
      - nodes - configure - add node and add host with credential (private key)
    - job execute
    - click on job
    - play around

init scripts
--------------------
item name; test pipeline
Strategy: log rotation
15 days
pipeline
pipeline script
hello world
script:
pipeline {
  agent ..
}

copy this code and go to vscode
and search jenkins and paste the code.
if you want to have miltiple stages, you can paste for n number of time and change stage hello1, hello2 and so on.
You can copy this code to jenkins and save.
Click on build now to execute the code.
You can also select jenkins + Maven.

jobname/pipeline syntax-> 
How to trigger jenkins job automatically.
How to access nexus repo?

click on job
- configuration
- build trigger
review the options
build periodically - its like cron job. batch type job. specify the schedule..
- trigger builds remotely (eg, from scripts)
  end point URL
jenkins_url/job/core-app-pipeline/build?token=sdfsdafsdfasf
http://ip:8080/job/core-app-pipeline/build?token=sdfsdafsdfasf
note: only login user can perform the build job
so you have to use the credentials.
- you can't use password but can use token.
click on API TOken
add new token / generate
http://user:token@job/core-app-pipeline/build?token=sdfsdafsdfasf
go to jenkins
- settings
web hooks
 add
payload URL
what time you want to trigger, review the options 
click on add webhook
job is automatically trigger.
=========================
launch new instance
- free tier
- t2.medium
- configure - add storage , security group port 8080, 80 ..
name this instance as nexus
go to security group and add a port
cutom tcp 8081 anywhere, 0.0.0.0/0

go to instnaces and click on nexus. verify its on running state. 
- connect - copy key 
how to create nexus repository
------------------------------
jar file generated will be uploaded to repo.
two approach
- normal approach
- docker hub
install docker package
$ apt install docker
$ apt update
$ docker

search nexus
sonatype nexus docker ..
$ docker run -d -p 8081:8081 --name nexus sonatype/nexus3
you can also use jenkins.
$ docker ps
$ copy nexus public ip address:8081
you got nexus repo
login: admin
pw: get from below command output. 
$ docker exec -it nexus cat /nexus-data/admin.password

it will promt you for new pw, 
- click next - finish

now, we have to upload our artifacts. 
- click on repository
- you can create or use existing repo
- click on repository
you have lots of options available. select based on your request.
maven has 3 type.
proxy - proxy to your repo. 
maven2 type
name: core-snapshots # backup option
layout policy : strict
blobstore(store): 
hosted: deployment ..
..
create repo

maven2
name: core-releases
other option not allowed..
disable redeploy
click on repo and you can copy.
Now, you can go back to your git and change the corporate repository.
<id> maven </id>

you can also take a snapshot version


=================== 
on nexus
Security
- proviledge
- roles
- users
- annonymous accesss
- LDAP
- Realms
- SSL certs

Roles -: role id: core-deployment-role
name: core-deployent-role
role description: core deployment
create role
and create users - create local user
- core user
email: test@best.com
passwod: status: active
done..
to upload aotumatically, use anonymous access...
setting.xml
maven 
github.com/devopsgsc/core-app/tree/dev
today
dynamic agent
webhook
nexus
- setup -> docker
- repo
- perissions
- settings.xml


54.177.243.80:8081
today




Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...