2023-03-10

Docker and Kubernetes

(Kubernetes aka k8s)



Kubernetes CLI

KubeCtl CLI doc



Kubernetes cheat sheet

K8s CLI Cheat sheet

CLI Quick ref

Docker Compose Kubernetes Cheat sheet



Kubernetes - Contexts

src: Docker: Kubernetes - intro - CLI example

kubectl config get-contexts

kubectl config use-context docker-desktop

kubectl get nodes

kubectl config view



Kubernetes - Orchestration example - running Pods:

src: Docker Kubernetes orchestration - short CLI reference

kubectl apply -f pod.yaml

kubectl get pods

kubectl logs demo

kubectl delete -f pod.yaml



Deploy to Kubernetes

(Containerize, Kubernetize, run)

Containerize

Containerize your application - Create image getting-started

git clone https://github.com/docker/getting-started.git

cd getting-started\app

copy con Dockerfile

# syntax=docker/dockerfile:1

FROM node:18-alpine

WORKDIR /app

COPY . .

RUN yarn install --production

CMD ["node", "src/index.js"]

EXPOSE 3000

^Z

docker build -t getting-started .

rem docker run -dp 3000:3000 getting-started

rem start http://localhost:3000

Kubernetize and run

src: Deploy to Kubernetes

Deploy, list, check, remote:

kubectl apply -f bb.yaml

kubectl get deployments

kubectl get services

start http://localhost:30001/

kubectl delete -f bb.yaml



Convert Docker Compose to Kubernetes

CLI kompose

Converts docker-compose.yaml to kubernetes-service.yaml



Kubernetes Dashboard

Web UI Dashboard

Create sample user

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

kubectl proxy

start http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

*

kubectl -n kubernetes-dashboard delete serviceaccount admin-user

kubectl -n kubernetes-dashboard delete clusterrolebinding admin-user



Kubernetes Dashboard - in Docker container (have not tested yet)

src: https://hub.docker.com/r/kubernetesui/dashboard

docker pull kubernetesui/dashboard



Namespaces

Namespaces intro

kubectl get namespaces

kubectl get namespaces --show-labels

Create DEV namespace:

kubectl create -f https://k8s.io/examples/admin/namespace-dev.json



Kubernetes config

src: StackOverflow

Config Example

--kubeconfig

KUBECONFIG=$HOME/.kube/config

~/.kube/config # Linux

%USERPROFILE%/.kube # Windows



Kubernetes config file

src: DevOpsCube: KubeConfig file

kubectl -n kube-system create serviceaccount devops-cluster-admin



Kubernetes short tutorial

Docker and Kubernetes at TutorialPoint



See also

*

Docker: Get started with Kubernetes - build docker k8s ready apps

Docker: Play with Kubernetes

Kubernetes - home

*

Kubernetes: deprecating Docker, switch to other containers (containerd or CRI-O) (Open Container Initiative)

Kubernetes: Dockershim deprecation FAQ

MS: Kubernetes vs Docker - cz



Docker limits cpu memory

Docker memory CPU limits (Windows)



for WSL2, create or open file:

%USERPROFILE%\.wslconfig

not: %HOMEPATH%\.wslconfig

Note: you have to save it in Linux LF (not Windows CRLF) mode



Add or update lines:

memory=3GB

processors=1

#kernel=C:\\temp\\myCustomKernel

#kernelCommandLine = vsyscall=emulate

swap=8GB

swapfile=C:\\temp\\wsl-swap.vhdx

pageReporting=true

#localhostforwarding=true

#nestedVirtualization=false

#debugConsole=true



src:

Microsoft Learn: example .wslconfig

src: Google search

StackOverflow: The Memory and CPU settings were removed for WSL2 integration



You have to stop all running WSL2 containers for changes to take effect.



Stop WSL2:

wsl --shutdown



2022-07-09

SQL basic course základní kurz


SQL basic course základní kurz

Fakt pro začátečníky, žádný pokročilý věci.


SQL na českých stránkách:

https://www.google.com/search?q=sql+site%3Acz


Spousta kvalitních výukových materiálů úplně zdarma a česky:

https://www.itnetwork.cz/mysql/mysql-tutorial-uvod-a-priprava-prostredi


Tady je úplný úvod do SQL:

https://www.itnetwork.cz/mysql/mysql-tutorial-vytvoreni-databaze-a-tabulky

Nemusíš to zdlouhavě číst, to v černém rámečku jsou příkazy jazyka.

Vždy na konci článku je odkaz na další díl.


Obrázky jsou otisky obrazovky z pracovního prostředí, zde PhpMyAdmin, které je jedno z možných.

Pro znalost a práci s SQL žádné takové prostředí nepotřebuješ, stačí ti znát ty příkazy v černém rámečku.


Souhrn základních SQL příkazů:

CREATE DATABASE `it_school`;

DROP DATABASE `it_school`;

CREATE TABLE user (

    id int NOT NULL AUTO_INCREMENT PRIMARY KEY,

    title_before varchar(20),

    first_name varchar(20),

    last_name varchar(20),

    title_after varchar(20),

    birth_date date,

);

INSERT INTO `user`

    (`title_before`, `first_name`, `last_name`, `title_after`, `birth_date`)

    VALUES (`Ing.`, `Pavel`, `Dvorak`, `PhD.`, `2000-12-31`);

INSERT INTO `user`

    (`title_before`, `first_name`, `last_name`, `title_after`, `birth_date`)

    VALUES (`Mgr.`, `Karel`, `Sovak`, NULL, `2001-11-30`),

    VALUES (`Bc.`, `Jiri`, `Mlady`, NULL, `2002-10-29`),

    VALUES (NULL, `Pavel`, `Stary`, NULL, `2003-09-28`);

SELECT * FROM USER;

UPDATE `user` SET `title_after` = `Doc.` WHERE `id` = 1;

SELECT * FROM USER;

DELETE FROM `user` WHERE `id` = 1;

DELETE FROM `user` WHERE `id` IN (2, 3, 5);


JavaScript programming basics


Základy programování v JavaScriptu


Úkol pro tebe. Připravil jsem ti hotový mini-program v JavaScriptu s Fibonacciho posloupností. Mám 2 varianty, rozhodni, která je lepší. Můžeš to upravovat rovnou v prohlížeči, výsledek je hned vidět vpravo.


Pro tyhle začátky je úplně jedno, zda Java nebo JavaScript, jde o princip a tady rovnou vidíš výsledek v pravém panelu.


Hotový program:

Fibonacci sequence:

Recursion:

https://jsbin.com/gopemiloki/edit?js,output

For loop:

https://jsbin.com/nakavuhuli/edit?js,output

https://jsbin.com/mayalijowa/edit?js,output


Úkol:

1. Podívej se na program, 1. i 2. variantu

1.a. Která varianta je lepší a proč?

2. Zkus si to naprogramovat sám znova (uprostřed šedé menu File / Clone, ať si nepřepíšeš originál, kdyžtak je originál ještě v příloze tohohle mailu)

3. Zkus nějakou změnu, úpravu (menu File / Clone)


Úkol:

Co je lepší a proč?

Zkus si to upravit.


Odkazy:

Co je to rekurze (nečti to celý)

https://cs.wikipedia.org/wiki/Rekurze_(programov%C3%A1n%C3%AD)

JavaScript cyklus for:

https://www.w3schools.com/js/js_loop_for.asp

- nečti to, jen klepni na Try it Yourself a zkus si něco sám


IT basic course základní kurz


Základní kurzy IT

Fakt základ, ukázky, nic pro profíky!


Keywords:

IT basic course 

IT základní kurz


Content:

Odkazy, poznámky, příklady základních úvodů do IT, programování, správy systémů atd.

Občas se mě lidi ptají, jak se naučit něco z IT, tak shromažďuji pár základních poznámek, klíčových slov a odkazů.


Články:

Základy programování v JavaScriptu (můj příklad v JavaScriptu)

Úvody do SQL (česky a s příkladama)


Algoritmy:

Fibonacci heap - Fibonacci heap CZ


2021-09-27

Git unplugged notes

Git unplugged notes



Rebase issue

# If someone rebases on public branch, after pull all others could see:

Your branch and 'origin/branch1' have diverged,

and have 2 and 3 different commits each, respectively.

Solution

git fetch origin

git reset --hard origin/main

src stackoverflow



Rebase issue

Your branch is ahead of 'origin/master' by 3 commits

Solution

git fetch -p # clean up local branches

git pull --rebase # pull and rebase my local commits on top of incoming

Better solution (unchecked)

Step 1 : git checkout branch1

Step 2 : git pull -s recursive -X theirs # merge strategies

Step 3 : git reset --hard origin/branch1



Rebase issue explained (long)

git rev-list --count --left-right branch1...upstream

git rev-list --count --left-right origin/master...HEAD

*

# to see if the local repository is ahead, push needed:

git rev-list origin..HEAD

# to see if the local repository is behind, pull needed:

git rev-list HEAD..origin

# if you have numbers for both, then the two repositories have diverged:

git rev-list --count --left-right origin/master...HEAD

src: stackoverflow

src: https://stackoverflow.com/a/40990959

src-long: https://stackoverflow.com/a/66981730



# squash - reset soft:

#git reset --soft master

git reset --soft origin/master

git add -A

git commit

git push --force



# squash - reset to merge-base:

git checkout branch1

git reset $(git merge-base master $(git branch --show-current))

git add -A

git commit

git push --force

# src: https://stackoverflow.com/questions/25356810/git-how-to-squash-all-commits-on-branch

# Note: git merge-base branch2 branch3



Squash

# squash - merge squash:

git checkout origin/master

git merge --squash origin/branch1

git commit

git push --force



Git branch_name vs refs

git show-ref origin/main

1. If $GIT_DIR/<refname> exists, that is what you mean (this is usually useful only for HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD and CHERRY_PICK_HEAD);

2. refs/<refname> if it exists;

3. refs/tags/<refname> if it exists;

4. refs/heads/<refname> if it exists;

5.  refs/remotes/<refname> if it exists;

6. refs/remotes/<refname>/HEAD if it exists.

src: stackoverflow.com

Long aside: how this all works (read only if sufficiently curious) :

src: stackoverflow.com



Git server repository (docker git repo)

RockStorm Git server on DockerHub - GitHub

Alpine Git client

JKarlos Docker Git server

Gogs and Podman Git server

Gogs Git server

Gogs by Pirates - GitHub like Git server

Gitea in Docker - demo - github

GitColony docker server - obsolete



Git server:

Google it:

https://www.google.com/search?q=gnu+gpl+git+server

Git server list - wiki:

https://en.wikipedia.org/wiki/Git#Git_server

Gerrit:

Home: https://www.gerritcodereview.com/

Wiki: https://en.wikipedia.org/wiki/Gerrit_(software)

GitOlite:

https://gitolite.com/gitolite/index.html

Wiki says: External projects like gitolite, which provide scripts on top of git software to provide fine-grained access control.

*

FLOSS:

Gogs

Gitea = fork of Gogs



Git Web interface self-hosted:

https://www.google.com/search?q=git+web+interface+self-hosted

Options – list – good overview:

https://www.cyberciti.biz/open-source/github-alternatives-open-source-seflt-hosted/

GitLab = web git, “Confluence” wiki, “Jira” tracker

https://gitlab.com/gitlab-org/gitlab-foss

Gitea – community fork of Gogs:

https://gitea.io/

Savannah = GNU = free software foundation (FSF)

http://savannah.gnu.org/projects/administration

GitBucket – Open source

https://github.com/gitbucket/gitbucket

Gogs - self hosted Git:

https://gogs.io/

*

Awesome Selfhosted:

https://github.com/awesome-selfhosted/awesome-selfhosted

GitWeb:

https://git-scm.com/book/en/v2/Git-on-the-Server-GitWeb

*

BitBucket.org

GitHub.com


Git web UI – including proprietary and closed-source:

https://www.slant.co/topics/1440/~best-self-hosted-web-based-git-repository-managers

https://www.slant.co/topics/425/~best-git-web-interfaces



Static web hosting on GitHub using Jekyll

(other Jekyll hostings, free-included)

GitHub is ready to host your static web site using Jekyll

Read  GitHub Pages intro.

Create public GitHub repo in format:

username.github.io

Exec:

git clone https://github.com/username/username.github.io

cd username.github.io

echo "Hello World" > index.html

git add --all

git commit -m "Initial commit"

git push -u origin main

Go to: https://username.github.io

*

Custom Domain and Domain Verification:

(sign in to your domain administration, i.e. ForPsi Domain Admin)

Verify ownership of example.com (on GitHub called apex domain):
Click your avatar on right-top corner
Settings
Pages
Verified domains
Click "Add a domain"

Then at GitHub pages level, following "domains" are yours:

www.example.com (custom sub domain)
blog.example.com
web.example.com
*.example.com
is only yours.

Warning: anything.web.example.com can be still used on GitHub Pages by any other user.

*

Configure Apex Domain

Steps:
Open GitHub
Go to your repo
Settings
Code and automation
Pages
Custom domain
type example.com (new CNAME file is created)
click Save (verification in progress)
-

Domain config:

Go to your domain administration, i.e. ForPsi Domain Admin
Create DNS records - either ALIAS, ANAME, or A (opt. AAAA for IPv6)
Test
dig example.com +noall +answer -t A
dig example.com +noall +answer -t AAAA

*

Configure SubDomain

*

GitHub Pages usage rules

See also:

Google search for Jekyll Hyde Web

Jekyll home