Follow the below steps
Build the docker image like below
docker build -t myimage:latest .
Tag your docker image with OpenShift registry
Build the docker image like below
docker build -t myimage:latest .
Tag your docker image with OpenShift registry
Before we start about Kubernetes let us first cover some of the basics of containers and what is the benefits of containerization.
A container is an executable package of software that includes everything needed to run it. Containerization is the packaging of software code with just the operating system (OS) libraries and dependencies required to run the code to create a single lightweight executable—called a container—that runs consistently on any infrastructure
Executable unit of software
OS Virtualization:
Small, fast, and portable
Benefits of container:
Kubernetes is an open-source container orchestration system for automating software deployment, scaling, and management. Google originally designed Kubernetes, but the Cloud Native Computing Foundation now maintains the project. Wikipedia
Create: $rebar3 new release <app name>
Compile: $rebar3 compile
Run: $rebar3 shell
Update dependency: $rebar3 update
Package: rebar3 as prod release
Run the package: $/<app name>/bin/<app name> foreground
Publishing to hex: $ rebar3 hex publish -r <test_repo>
ref: https://rebar3.readme.io/docs/commands
Creating node:
$erl -name server@192.168.0.149 -setcookie mathcluster
$erl -name client@192.168.0.90 -setcookie mathcluster
Test the connection:
>net_adm:ping('server@192.168.0.149').
List the nodes: >nodes().
Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecoms, banking, e-commerce, computer telephony and instant messaging. Erlang's runtime system has built-in support for concurrency, distribution and fault tolerance.
https://www.erlang-solutions.com/downloads/
https://tecadmin.net/install-erlang-on-centos/
Keystone/ key replace:
lists:forach
1> Print = fun(Value) -> io:format("~p~n",[Value]) end.
#Fun<erl_eval.44.65746770>
2> List = [1,2,3,4,5,6].
[1,2,3,4,5,6]
3> lists:foreach(Print, List).
1
2
3
4
5
6
Ok
lists:map
> Square = fun(Value)->Value*Value end.
#Fun<erl_eval.44.65746770>
> lists:map(Square, List).
[1,4,9,16,25,36]
OR
> [Square(Value) || Value <- List].
> [Value * Value || Value <- List].
> List2 = [10 | List].
[10,1,2,3,4,5,6]
In list difference between | and || are, | concat and || map operation.
> LessThanFive = fun(Value)-> (Value<5) and (Value>=0) end.
#Fun<erl_eval.44.65746770>
> lists:filter(LessThanFive,List).
[1,2,3,4]
> [Value || Value <- List, Value<5, Value>=0].
[1,2,3,4]
> Weather = [{toronto, rain}, {montreal, storms}, {london, fog},
> {paris, sun}, {boston, fog}, {vancouver, snow}].
[{toronto,rain},
{montreal,storms},
{london,fog},
{paris,sun},
{boston,fog},
{vancouver,snow}]
>
> FoggyPlaces = [X || {X, fog} <- Weather].
[london,boston]
Module | Syntax |
---|---|
maps:new/1 | #{} |
maps:put/3 | Map#{Key => Val} |
maps:update/3 | Map#{Key := Val} |
maps:get/2 | Map#{Key} |
maps:find/2 | #{Key := Val} = Map |
Sending message to a process using !
> self() ! test1.
test1 message will be waiting in the mail box
You can retrieve by receive block
> receive X -> X end.
> Pid=spawn(bounce,report,[]).
> Pid ! “Hello World”.
receive XXX -> XXX end.
exit(whereis(registered pid), kill).
flush().
erlang:process_info(self(), messages)
spawn(?ModuleName, <Function name> , <argument>)
register(<name to be registered> ,<Process id>).
whereis/1 to find the process
unregister/1. To unregister a process
Parent = ?current_span_ctx,
io:format("Parent: ~p~n",[Parent]),
Span2Ctx = Parent#span_ctx{trace_id=TraceId},
?set_current_span(Span2Ctx),
Records let you create data structures that use names to connect with data rather than order
For example
-record(planemo, {name, gravity, diameter, distance_from_sun}).
-record(tower, {location, height=20, planemo=earth, name}).
The command rr (for read records) lets you bring this into the shell:
1> rr("records.hrl").
[planemo,tower]
> Tower1=#tower{location="NYC", height=241, name="Woolworth Building"}.
Accessing value from a record
> Tower1#tower.planemo.
Pattern matching to extract value:
#tower{location=L5, height=H5} = Tower1.
Update record value:
Tower1a=Tower1#tower{height=512}.
Erlang Term Storage (ETS) is a simple but powerful in-memory collection store.
Creating and Populating a Table
PlanemoTable=ets:new(planemos, [named_table, {keypos, #planemo.name}]),
ets:info(PlanemoTable).
To see what’s in the table
ets:tab2list(<record name eg, planemos>).
Lookup: ets:lookup(planemos,eris).
11> Result=hd(ets:lookup(planemos,eris)).
#planemo{name = eris,gravity = 0.8,diameter = 2400,
distance_from_sun = 10210.0}
12> Result#planemo.gravity.
Overwriting Values
ets:insert(planemos, #planemo{ name=mercury,
gravity=3.9, diameter=4878, distance_from_sun=57.9 }).
true
ets:fun2ms
ets:match
ets:select
ets:delete
ets:first
ets:next
ets:last
mnesia:create_schema([node()]).
mnesia:start().
mnesia:table_info/2
mnesia:transaction(fun() -> mnesia:read(planemo,neptune) end).
mnesia:first
mnesia:next
(If you want to change where Mnesia stores data, you can start Erlang with some extra options: erl -mnesia dir " path ". The path will be the location Mnesia keeps any disk-based storage.)
Apart from the setup, the key thing to note is that all of the writes are contained in a fun that is then passed to mnesia:transaction to be executed as a transaction. Mnesia will restart the transaction if there is other activity blocking it, so the code may get executed repeatedly before the transaction happens. Because of this, do not include any calls that create side effects to the function you’ll be passing to mnesia:transaction, and don’t try to catch exceptions on Mnesia functions within a transaction. If your function calls mnesia:abort/1 (probably because some condition for executing it wasn’t met), the transaction will be rolled back, returning a tuple beginning with aborted instead of atomic.
Query list:
mnesia:transaction(
fun() ->
qlc:e(
qlc:q( [X || X <- mnesia:table(planemo)] )
)
end
)
mnesia:transaction(
fun() ->
qlc:e(
qlc:q( [{X#planemo.name, X#planemo.gravity} ||
X <- mnesia:table(planemo),
X#planemo.gravity < 9.8] )
)
end
)
mnesia:transaction(
fun() ->
qlc:e(
qlc:q( [X || X <- mnesia:table(planemo),
X#planemo.gravity < 9.8] )
)
end
)
OTP is set of Erlang libraries and design principles providing middle-ware to develop these systems. It includes its own distributed database, applications to interface towards other languages, debugging and release handling tools.
OTP formalizes those activities, and a few more, into a set of behaviors (or behaviours—this was originally created with British spelling). The most common behaviors are gen_server (generic server) and supervisor, though gen_fsm (finite state machine) and gen_event are also available. The application behavior lets you package your OTP code into a single runnable (and updatable) system.
Application Behavior
Async Events
Sync Events
{ok, Pid} = drop_sup:start_link().
1> c(drop_app).
{ok,drop_app}
2> code:add_path("ebin/").
true
3> application:load(drop).
ok
4> application:loaded_applications().
[{kernel,"ERTS CXC 138 10","2.15.2"},
{drop,"Dropping objects from towers","0.0.1"},
{stdlib,"ERTS CXC 138 10","1.18.2"}]
5> application:start(drop).
ok
6> gen_server:call(drop, 60).
{ok,34.292856398964496}
Rebar3 is an Erlang tool that makes it easy to create, develop, and release Erlang libraries, applications, and systems in a repeatable manner. If you are from java programming, it is like maven. Hex is the repository to publish erlang library and searching, downloading library.
For installing rebar3
https://github.com/erlang/rebar3
https://rebar3.readme.io/docs/getting-started
PATH=$PATH:$HOME/bin
export PATH=$PATH:~/.cache/rebar3/bin
Compile with rebar3: $rebar3 compile
Running with rebar3: $rebar3 shell
Publishing to hex: $ rebar3 hex publish -r test_repo
Erlang commands:
q() | Quits the shell and the Erlang runtime. |
c(file) | Compiles the specified Erlang file. |
b() | Displays all variable bindings. |
f() | Clears all variable bindings. |
f(X) | Clears specified variable binding. |
h() | Prints the history list of commands. |
e(N) | Repeats the command on line N. |
v(N) | The return value of line N. |
catch_exception(boolean) | Sets how strict the shell will be in passing errors. |
rd(Name, Definition) | Defines a record type Name with contents specified by Definition. |
rr(File) | Defines record types based on the contents of File. |
rf() | Clears all record definitions. Can also clear specific definitions. |
rl() | Lists all current record definitions. |
pwd() | Gets the present working directory. |
ls() | Lists files at the current location. |
Dockerizing:
Git 2.0 installation:
Install java 11: yum -y install java-11-openjdk java-11-openjdk-devel