Wednesday, February 24, 2021

Day22- Kubernetes Package Manager - Chart-Helm - 2-24-2021

 Day22- Kubernetes Package Manager - Chart-Helm - 2-24-2021


Class Notes


- Used for k8s to manage package - Helm

Package is called chart in k8s term.

How to create package chart.
- Custom chat - how to create your own chart.

1. Login to your k8s server
we have 1 master and 3 worker nodes

By default, you run everything on master.
- All the commands from master or run from workstation

# kc get nodes
# kc cluster-info
gives you api server info ip:port
kubeDNS - url


App -> k8s cluster ->
huge shift on how we use k8s cluster.

to create entire pipeline end to end, k8s is not the best tool
- for end to end pipeline -> on top of k8s that runs on top of it with extra features
  which k8s never provides is openShift.

K8s - OpenShift -> 12.5K

App
--> Deployment
--> SVC
--> Secret
--> PVC
--> CM

we may have to create these above resources to launch any application

Test -> yaml file...

Final approach is to deploy app..

package - myapp

rather than yaml file, just specify the package which will standardize the task.

its like an archive say tar file.
it helps to have a same env across the environment.

We may have different version, we can have a package with v1 and also with v2
which gives user to pick the version they want.

parameterize.. - you can make pkg parameterize which means you specify the version of the software, change port, change size on the fly..

while launching the package you can change these values such as port, size...


Some cases you may need 2 svc, 2 storage, 2 ports, php/mysql ...
say wordpress application..


Install package, remove package
-specify dependent packages...

helm is the packager for kubernetes..
- its not from k8s but from third party.

package is called chart in kubernetees term.
Terminology is chart.

google for chart (package), you will find for
- repo
- chart for jumbla,
- php, jinkins

double click and install -> download and install

You can create your own custom chart.
- you create your own.

We will learn how to create chart (pkg)

1. Install helm
- on your work space so it can be your worstation or master node
- We will be using master node to run commands, so lets inttall it there
google for installation for helm
helm.sh/docs/intro/install

Windows
# choc install

Install help from binary
- click on download the link
- Helm comes with 2 version v2 and v3
- Working on v2 and v3 is totally different.

we install helm (a client program) on user computer or environemnt.
- on k8s you have to install a server program which takes request from helm and install on nodes
- The name of the program is tiller.
for v2, you need tiller program which comes in POD.
This model is obsoluted.

v3 does not need to contact tiller.
- it can direct contact api server.

helm init - userd in v2 - it sets up tiller

we will be using helm 3.5.2
link takes you to github and download helm-v3.5.2-linux-amd64.tar.gz
# tar -xvzf heml-v3...

# cp linux-amd64/helm /usr/bin

On windows, just double click to install.

# helm -> you will see the output
# helm version

you can connect with k8s master and start working on it..

# ls .kube/config

heml uses .kube/config file.


Custom Chart -> create a very small program

# mkdir /ws; cd ws
all the pkg we are going to create going to be stored here.

Create pkg for all softwares
# mkdir myweb    # dir name is the name of pkg name . here myweb is going to be name of pkg
# mkdir myweb jenkins mysqldb
# cd myweb
create config file for chart
# vi Chart.yaml
note: c is in capital letter and extension is .yaml

it looks for syntax

There are some key words you have to specify


apiVersionL v1
name: myweb    # name of your chart - very imp line
version: 0.1    # very important lines
appVersion: 1.1
description: This is my apache server pkg # you can write author and much more..

# google for helm - helm char.yaml variables

so, we just created a Chart.yaml file under myweb which is going to be name of the package.

we just created, not installed yet.

check if any pkg - helm installed
# heml list
it does not list any

now, lets see how to install
# helm install myweb/
it fails must provide a name.
 lets try again
helm install myweb myweb/
# heml list
you see it is installed


hwere name came from?
# cat myweb/Chart.yaml
from name section
its kind of metadata.


on k8s server
# kc get pods
# kc delete all --all


you don't have to run kubectl create command or create yaml file to deploy app.
you can simply instal it

Remove the local installed sfotware
# helm list
# helm delete myweb

Now, lets start again from web folder.
#

For app web need,
App
--> Deployment
--> SVC
--> Secret
--> PVC
--> CM

The resources that are needed can be included in templates.
all required files

# mkdir templates
# kc create deployment myd --image=httpd:v1 --dry-run -o yaml >deployment1.yaml
# kc get pods
# kc get deploy

so, we have myweb
- we add one resource that is deployment... you either copy, or get it through dry-run..
we will add more resources here. we just added more resources

# helm install myweb myweb/

status: Deployed

# helm list

this chart contains one resources.

This s launch using helm using deployment.

We can launch a service too.

we can add more respurces on templetes

# kc expose deploy myd --port=80 --type=NodePort --dry-run -o yaml > service.yaml

we previously had one resource and we just added new resource.

# kc get svc

# vi service.yaml

before deleting verify with your team..

# helm list
# helm install myweb myweb

# kc get svc
# heml upgrade myweb/

two arguement needed
- release you want to upgrade
  new version of chart.

#

updated version..
# vi Chart.yaml
apiVersionL v1
name: myweb    # name of your chart - very imp line
version: 0.2    # very important lines
appVersion: 1.1
description: This is my apache server pkg # you can write author and much more..

# helm list
# helm upgrade myweb
# helm upgrade myweb myweb

# helm list

# kc get deploy
# kc get svc

you keep on adding the features..

#
If you want to update replicas -> change on your deployment and change it to 2 or 3 or 4 ...

if you have to remove

# helm rollback myweb

# kc get pods
# kc get svc
# heml history myweb

you wil see it

You can roll back
# helm rollback myweb 3

# helm history myweb

# kc get svc



==========

# pwd
/ws/myweb
# vi templates/values.yaml
replicaCount: 3

# edit your deployment
# vi deployment
change spec: replicas

  replicas: {{.Values. repllicaCount }} # variable is in values file.  # this is also called parameterization


# heml list
# helm delete myweb
# heml list
# kc get pods


# helm install kbws myweb/
# kc get pods
# heml delete kbws

can we see any values?
# helm show values myweb
it shows here, parameter set.
replicaCount: 3

change strategy of deployment.

# heml install kbweb myweb/ --set replicaCount=5

or
# vi /ws/myweb/templates/service.yaml
# heml show values myweb/

you want to something on service

# vi templates/values.yaml
replicaCount: 3
myservice:
  type: NodePort
  port: 80 or 2222
# vi myweb/template/service

go to type spec section
type: {{ .Values.myservice.type }}

Also change nodeport

NodePort: {{ .Values.myservice.port }}


# heml list
# heml upgrade kbws myweb/

Pass value on the fly,
# helm upgrade kbws myweb/ --set myservice.port=30001

google for kube nodeport


# kc get svc


you can search and google and use other people chart.

helm -> go to get charts artifacthub.io ->community folks

search download and install

say search wordpress -> verified publishers...

Task: create a chart for the technology

open an account on artifect.io and upload your pkg there..


# helm repo list
no repo to show

You have to Configure repo


Read

# helm repo add bitnami https://charts.bitnami.com/bitnami

search software on this repo
# heml repo list
# heml search hub workpress
# helm install my-release bitnami/wordpress
# kc get deploy
# kc get pods

# heml install my-release bitnami/wordpress

# kc get pvc
# kc get sc, svc,



No comments:

Post a Comment

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. ...