tag:blogger.com,1999:blog-45689344030850481792024-03-17T20:03:21.709-07:00Help Guide For Software EngineerSujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.comBlogger246125tag:blogger.com,1999:blog-4568934403085048179.post-42537611662231968122023-08-25T03:12:00.003-07:002023-08-25T03:12:17.987-07:00Mongo Shell Commands<p> Following commands can be used in mongo db shell.</p><p><b>show dbs</b></p><p></p><ul style="text-align: left;"><li>list of all the databases</li></ul><p></p><p><b>use shops</b></p><p></p><ul style="text-align: left;"><li>switch to a specific database or creates a database (shops) </li></ul><p></p><p><b>db.createCollection("products")</b></p><p></p><ul style="text-align: left;"><li>creating the collection (products)</li></ul><p></p><p><b>show collections</b></p><p></p><ul style="text-align: left;"><li>display a list of all the collections </li></ul><p></p><p><b> db.products.insertOne({"name":"prod_name1"})</b></p><p></p><ul style="text-align: left;"><li>insert a document into a collection</li></ul><p></p><p><b>db.products.insertMany([{"name":"prod_name2"},{"name":"prod_name3"}])</b></p><p></p><ul style="text-align: left;"><li>insert many products in one command</li></ul><p></p><p><b>db.products.insertOne({"name":"test_prod4","vendor":{"name":"vendor_1","address":"address_1"}})</b></p><ul><li>insert many products in one command with multiple objects</li></ul><p><b>db.student.insertOne({"name":"test_prod5",,"vendor":{"name":"vendor_1","address":{"address_line1":"line1","address_line2":"line2","city":"city"}}})</b></p><ul><li>insert many products in one command with multiple objects</li></ul><p><b>db.products.find()</b></p><p></p><ul style="text-align: left;"><li>retrieve all documents</li></ul><p></p><p><b>db.products.update({name:"</b><b>test_prod1</b><b>"},{$set:{price:"120.00"}})</b></p><p></p><ul style="text-align: left;"><li>update a document in the "products" collection. updates first document only for <b>name:"</b><b>test_prod1</b><b>"</b> </li></ul><p></p><p><b>db.student.update({"name":"test_6"},{$set:{age:26}},{multi:true})</b></p><p></p><ul style="text-align: left;"><li>updating all document</li></ul><p></p><p><b>db.student.update({_id:ObjectId("64dc5856e4cebb07084d8c45")},{$unset:{price:"120.00"}})</b></p><p></p><ul style="text-align: left;"><li>updating the document using object id and remove price attribute</li></ul><p></p><p><b>db.teaches.update({"th_name":"test_th_2"},{$set:{student:[{"std_name":"test_1"},{"std_name":"test_2"}]}})</b></p><p></p><ul style="text-align: left;"><li>adding the Student object field</li></ul><p></p><p><b>db.student.find({$and:[{"name":"test_4"},{"age":"40"}]})</b></p><p></p><ul style="text-align: left;"><li>AND operation. returns all objects with name =test_4 and age=40</li></ul><p></p><p><b>db.student.find({$or:[{"name":"test_4"},{"name":"test_2"}]})</b></p><p></p><ul style="text-align: left;"><li>OR operation and returns name = test_2 or test_4</li></ul><p></p><p><b>db.student.drop()</b></p><p></p><ul style="text-align: left;"><li>drop student collection</li></ul><p></p><p><b>db.teaches.remove({"name":"t_name1"})</b></p><p></p><ul style="text-align: left;"><li>remove document name =t_name1</li></ul><p></p><p><b>db.teaches.deleteOne({"name":"t_name2"})</b></p><p></p><ul style="text-align: left;"><li>remove one document with name=t_name2</li></ul><p></p><p><b>db.student.aggregate([{$lookup:{from:"teaches",localField:"std_name",foreignField:"student.std_name",as:"studentDetails"}}])</b></p><p></p><ul style="text-align: left;"><li>aggregation operation in MongoDB to join the "student" collection with the "teaches" collection</li></ul><p></p><p><b>db.mycol.find().pretty() </b></p><p></p><ul style="text-align: left;"><li>return results in formatted way</li></ul><p></p><div><br /></div><p><br /></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-1683251691357345942023-07-19T20:52:00.000-07:002023-07-19T20:52:22.977-07:00<p><span style="font-family: courier;">#!/bin/bash</span></p><p><span style="font-family: courier;">ps -ef |grep "java -jar" > /apps/appcheck</span></p><span class="ui-provider fz b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak" dir="ltr"><p><span style="font-family: courier;">x=$(cat /apps/appcheck |grep "TestApp.jar" |wc -l)<br />
echo $x</span></p><p><span style="font-family: courier;"> if [ $x = 0 ]<br /></span></p><div style="text-align: left;"><span style="font-family: courier;">
then<br /></span><span style="font-family: courier;">
date<br /></span><span style="font-family: courier;"><span> </span><span> </span><span> </span><span> echo ""<br /></span></span><span style="font-family: courier;"> echo "starting... check logs "<br /></span><span style="font-family: courier;">
cd /apps/sujith/test<br /></span><span style="font-family: courier;">
nohup java -jar -Xms128m -Xmx256m TestApp.jar 2 >> TestApp.log &<br /></span><span style="font-family: courier;"> elif [ $x = 1 ]</span></div><p></p><p><span style="font-family: courier;">
then<br />
date<br />
echo "stopping..."<br />
cat /apps/appcheck|grep "TestApp.jar" | awk -F " " '{print $2}' | xargs kill -9<br />
echo "stopped"<br />
date<br />
echo "starting..."<br />
cd /apps/sujith/test<br />
nohup java -jar -Xms128m -Xmx256m ThripleNine.jar 2>> TestApp.log &</span></p><p><span style="font-family: courier;"> else<br />
echo "error occurred. check."</span></p><p><span style="font-family: courier;"> fi</span></p><p><br /></p></span>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-77606115343996086002023-06-27T01:04:00.004-07:002023-06-27T01:08:03.360-07:00kubernetes pod sample files<div style="line-height: 19px;"><div style="white-space: pre;"><div style="line-height: 19px;"><div><b><span style="font-family: inherit;"><span style="background-color: white;">simple </span><span style="background-color: white;">nginx pod</span></span></b></div><div><b><span style="font-family: inherit;"><span style="background-color: white;"><br /></span></span></b></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">v1</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Pod</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-pod</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"> <span style="color: #569cd6;">tier</span>: <span style="color: #ce9178;">dev</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-container</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px;"><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx</span></span></div></div></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;"><br /></span></span></div><div><span style="background-color: white;"><span style="white-space: pre;"><b><span style="font-family: inherit;">multiple containers in one pod</span></b></span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white; color: #569cd6;"><br /></span></div><div><div style="line-height: 19px;"><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">v1</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Pod</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-caching-server</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">purpose</span>: <span style="color: #ce9178;">demonstrate-multi-container-pod</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-container1</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx</span></span></div><span style="background-color: white; color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><br /></span><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">busybox-container2</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">busybox</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">command</span>: </span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> - <span style="color: #ce9178;">sleep</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> - <span style="color: #ce9178;">"3600"</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="color: #ce9178;"><br /></span></div><div style="white-space: pre;"><b><span style="font-family: inherit;">replica controller </span></b></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white; color: #ce9178;"><br /></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><div style="line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">ReplicationController</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-rc</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">replicas</span>: <span style="color: #b5cea8;">3</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-pod</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx-app</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-container</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">ports</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">containerPort</span>: <span style="color: #b5cea8;">80</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">selector</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx-app</span></span></div></div></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="color: #ce9178;"><br /></span></div><div style="white-space: pre;"><span style="background-color: white;"><b><span style="font-family: inherit;">replica set </span></b></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white; color: #ce9178;"><br /></span></div><div style="white-space: pre;"><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">apps/v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">ReplicaSet</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-rs</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">replicas</span>: <span style="color: #b5cea8;">3</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-pod</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx-app</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">tier</span>: <span style="color: #ce9178;">frontend</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-container</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">ports</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">containerPort</span>: <span style="color: #b5cea8;">80</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">selector</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">matchLabels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx-app</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">matchExpressions</span>:</span></div><div><span style="background-color: white;"> - {<span style="color: #569cd6;">key</span>: <span style="color: #ce9178;">tier</span>, <span style="color: #569cd6;">operator</span>: <span style="color: #ce9178;">In</span>, <span style="color: #569cd6;">values</span>: [<span style="color: #ce9178;">frontend</span>]}</span></div><span style="background-color: white;"><br /></span></div><div style="line-height: 19px;"><span style="background-color: white;"><b><span style="font-family: inherit;">daemon set</span></b></span></div><div style="line-height: 19px;"><span style="background-color: white;"><b><span style="font-family: inherit;">daemon set guarantee to up and run one instance in every node</span></b></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px;"><span style="background-color: white;"><br /></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px;"><div style="line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">apps/v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">DaemonSet</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">fluentd-ds</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">fluentd</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">fluentd</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">gcr.io/google-containers/fluentd-elasticsearch:1.20</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">selector</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">matchLabels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">fluentd</span></span></div></div></div></div><div style="white-space: pre;"><b><span style="font-family: inherit;"><br /></span></b></div><div style="white-space: pre;"><b><span style="font-family: inherit;">up and run pods for special nodes only using daemon set(diskType=ssd)</span></b></div><div style="font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white; color: #ce9178;"><br /></span></div><div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">apps/v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">DaemonSet</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-ds</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-container</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">nodeSelector</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">disktype</span>: <span style="color: #ce9178;">ssd</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">selector</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">matchLabels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx</span></span></div><span style="background-color: white;"><br /></span></div><div style="color: #cccccc; line-height: 19px; white-space: pre;"><span style="background-color: white; font-family: inherit;"><b><br /></b></span></div><div style="line-height: 19px; white-space: pre;"><span style="background-color: white;"><span style="font-family: inherit;"><b>batch execution pod. it will print 9 to 1 when execution.</b></span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><span style="background-color: white;"><br /></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">batch/v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Job</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">countdown</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">countdown</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">counter</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">centos:7</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">command</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #ce9178;">"bin/bash"</span></span></div><div><span style="background-color: white;"> - <span style="color: #ce9178;">"-c"</span></span></div><div><span style="background-color: white;"> - <span style="color: #ce9178;">"for i in 9 8 7 6 5 4 3 2 1 ; do echo $i ; done"</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">restartPolicy</span>: <span style="color: #ce9178;">Never</span></span></div></div></div><div style="line-height: 19px; white-space: pre;"><span style="background-color: white;"><b><span style="font-family: inherit;"><br /></span></b></span></div><div style="line-height: 19px; white-space: pre;"><span style="background-color: white;"><b><span style="font-family: inherit;">nginx deployment pod</span></b></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><span style="background-color: white;"><br /></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">apps/v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Deployment</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-deploy</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx-app</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">replicas</span>: <span style="color: #b5cea8;">3</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx-app</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-container</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">ports</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">containerPort</span>: <span style="color: #b5cea8;">80</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">selector</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">matchLabels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx-app</span></span></div></div></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><span style="background-color: white;"><br /></span></div><div style="line-height: 19px; white-space: pre;"><span style="background-color: white;"><span style="font-family: inherit;"><b>redis deployment using Recreate</b></span></span></div><div style="line-height: 19px; white-space: pre;"><span style="font-family: inherit;"><b><span style="background-color: white;"><span>In "</span></span>Recreate", it will terminate all containers at once and restart required containers.</b></span></div><div style="line-height: 19px; white-space: pre;"><b><br /></b></div><div style="line-height: 19px; white-space: pre;"><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">apps/v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Deployment</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">redis-deployment</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">redis</span></span></div><span style="background-color: white;"><br /></span><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">replicas</span>: <span style="color: #b5cea8;">10</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">selector</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">matchLabels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">redis</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">strategy</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">type</span>: <span style="color: #ce9178;">Recreate</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">redis</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">redis-container</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">redis:5.0</span></span></div><span style="background-color: white;"><br /></span></div><div style="line-height: 19px;"><span style="background-color: white;"><b><span style="font-family: inherit;">redis deployment using RollingUpdate</span></b></span></div><div style="line-height: 19px;"><b><span style="font-family: inherit;"><span style="background-color: white;">in "</span><span style="background-color: white;">RollingUpdate", requested number of containers will be updated. </span></span></b></div><div style="line-height: 19px;"><span style="background-color: white;"><b><span style="font-family: inherit;">new instance will up and old instance will down in this scenario.</span></b></span></div></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><span style="background-color: white;"><br /></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">apps/v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Deployment</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">redis-deployment</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">redis</span></span></div><span style="background-color: white;"><br /></span><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">replicas</span>: <span style="color: #b5cea8;">15</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">selector</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">matchLabels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">redis</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">strategy</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">type</span>: <span style="color: #ce9178;">RollingUpdate</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">rollingUpdate</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">maxSurge</span>: <span style="color: #b5cea8;">2</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">maxUnavailable</span>: <span style="color: #b5cea8;">2</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">minReadySeconds</span>: <span style="color: #b5cea8;">10</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">redis</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">redis-container</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">redis:6.0</span> <span style="color: #6a9955;">#Upgrade to 6.0 --> 6.0.16 --> 6.2.6</span></span></div><span style="background-color: white;"><br /></span></div></div><div style="line-height: 19px;"><b><span style="font-family: inherit;"><span style="white-space: pre;">volume</span><span style="background-color: white; white-space: pre;"> usage</span></span></b></div><div style="line-height: 19px;"><span style="background-color: white;"><span style="white-space: pre;"><b><span style="font-family: inherit;">when using volume, it can replicate to every containers config in pod file</span></b></span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><span style="background-color: white;"><br /></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Pod</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">sidecar-pod</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">volumes</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">logs</span> </span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">emptyDir</span>: {}</span></div><span style="background-color: white;"><br /></span><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">app-container</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">alpine</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">command</span>: [<span style="color: #ce9178;">"/bin/sh"</span>]</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">args</span>: [<span style="color: #ce9178;">"-c"</span>, <span style="color: #ce9178;">"while true; do date >> /var/log/app.log; sleep 5; done"</span>]</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">volumeMounts</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">logs</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">mountPath</span>: <span style="color: #ce9178;">/var/log</span></span></div><div><span style="background-color: white;"> </span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">log-exporter-sidecar</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">ports</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">containerPort</span>: <span style="color: #b5cea8;">80</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">volumeMounts</span>:</span></div><div><span style="background-color: white;"> - </span><span style="background-color: white; color: #569cd6;">name</span><span style="background-color: white;">: <span style="color: #ce9178;">logs</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">mountPath</span>: <span style="color: #ce9178;">/usr/share/nginx/html</span></span></div></div></div><div style="line-height: 19px; white-space: pre;"><span style="background-color: white;"><b><span style="font-family: inherit;"><br /></span></b></span></div><div style="line-height: 19px; white-space: pre;"><span style="background-color: white;"><b><span style="font-family: inherit;">volume "emptyDir" usage </span></b></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><span style="background-color: white;"><br /></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><div><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">v1</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Pod</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-emptydir</span></span></div><div><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-container</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">volumeMounts</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">test-vol</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">mountPath</span>: <span style="color: #ce9178;">/test-mnt</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">volumes</span>:</span></div><div><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">test-vol</span></span></div><div><span style="background-color: white;"> <span style="color: #569cd6;">emptyDir</span>: {}</span></div></div></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; line-height: 19px; white-space: pre;"><span style="background-color: white;"><br /></span></div></div></div></div><div style="white-space: pre;"><span style="background-color: white;"><b><span style="font-family: inherit;">nginx deploymnet with 2 replicas </span></b></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;"><br /></span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;">apiVersion</span>: <span style="color: #ce9178;">apps/v1</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;">kind</span>: <span style="color: #ce9178;">Deployment</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;">metadata</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx-deployment</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"><span style="color: #569cd6;">spec</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">selector</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">matchLabels</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">replicas</span>: <span style="color: #b5cea8;">2</span> <span style="color: #6a9955;"># tells deployment to run 2 pods matching the template</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">template</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">metadata</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">labels</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">app</span>: <span style="color: #ce9178;">nginx</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">spec</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">containers</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> - <span style="color: #569cd6;">name</span>: <span style="color: #ce9178;">nginx</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">image</span>: <span style="color: #ce9178;">nginx:1.14.2</span></span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> <span style="color: #569cd6;">ports</span>:</span></div><div style="color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><span style="background-color: white;"> - <span style="color: #569cd6;">containerPort</span>: <span style="color: #b5cea8;">80</span></span></div><span style="background-color: white; color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre;"><br /></span></div><p><span style="background-color: white;"> </span></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-15900516659425721322023-06-02T04:01:00.001-07:002023-06-27T00:05:27.667-07:00Kubernetes Commands<p style="text-align: left;"><span style="font-family: courier;">kubectl get nodes</span><b> returns available nodes in k8s cluster</b></p><p style="text-align: left;"><span style="font-family: courier;">kubectl get po</span> <b>returns available pods in k8s cluster</b></p><p style="text-align: left;"><span style="font-family: courier;">kubectl get po -o wide</span> <b>return ip address and other details of pod </b></p><p style="text-align: left;"><span style="font-family: courier;">kubectl create -f poddemo.yml</span> <b>create pod using yml file. this will create a pod with nginx</b></p><div style="text-align: left;"><p>Sample yaml file for pod creation </p><blockquote>apiVersion: v1<br />kind: Pod<br />metadata:<br /> name: nginx-pod<br /> labels:<br /> app: nginx<br /> tier: dev<br />spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx</blockquote></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><span style="font-family: courier;">kubectl describe pod nginx-pod</span> <b>returns details about pod</b></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><span style="font-family: courier;">kubectl delete pod nginx-pod</span> <b>delete pod nginx-pod</b></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><span style="font-family: courier;">kubectl delete pod --all </span><b>delete all pods</b></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><span style="font-family: courier;">kubectl expose pod nginx-pod --type="NodePort" --port=8080</span> <b>expose pod in 8080 port as a service</b></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><span style="font-family: courier;">kubectl get svc </span><b>returns services exposed</b></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><span style="font-family: courier;">kubectl delete svc nginx-pod</span> <b>delete service nginx-pod</b></div><div style="text-align: left;"><b><br /></b></div><div style="text-align: left;"><span style="font-family: courier;">kubectl exec -it nginx-caching-server bash </span><b>access to </b><b>nginx-caching-server bash terminal</b></div><div style="text-align: left;"><b><br /></b></div><div style="text-align: left;"><span style="font-family: courier;">kubectl exec -it nginx-caching-server -c busybox-container2 sh </span><b>access </b><b>nginx-caching-server pod's container "</b><b>busybox-container2" for sh</b></div><div style="text-align: left;"><b><br /></b></div><div style="text-align: left;"><span style="font-family: courier;">kubectl get rc </span><b>returns returns replica controllers</b></div><div style="text-align: left;"><b><br /></b></div><div style="text-align: left;"><span style="font-family: courier;">kubectl get rs</span><b> returns replica set</b></div><div style="text-align: left;"><b><br /></b></div><div style="text-align: left;"><span style="font-family: courier;">kubectl scale rc nginx-rc --replicas=5</span><b> scale replica controller size to 5 for </b><b>nginx-rc</b></div><div style="text-align: left;"><b><br /></b></div><div style="text-align: left;"><span style="font-family: courier;">kubectl delete rc --all</span><b> delete all replica controllers</b></div><div style="text-align: left;"><b><br /></b></div><div style="text-align: left;"><span style="font-family: courier;">kubectl delete rs --all</span><b> </b><b>delete all replica sets</b></div><div style="text-align: left;"><b><br /></b></div><div style="text-align: left;"><div><span style="font-family: courier;">kubectl label nodes node2 diskType=ssd</span><b> change node 2's diskType to ssh</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl get nodes --show-labels</span><b> returns all labels</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl get job</span><b> return batch job details</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl describe jobs countdown </span><b>retrieve details about </b><b>countdown pod's job</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl logs countdown-rmc97</span><b> returns logs of "</b><b>countdown-rmc97" container</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl get deploy </span><b>returns deployments</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl delete deploy --all</span><b> delete all deployments </b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl describe deploy nginx-deploy</span><b> returns details of "</b><b>nginx-deploy" deployment</b></div><div><b><br /></b></div><div><div><span style="font-family: courier;">kubectl set image deploy nginx-deploy nginx-container=nginx:1.9.1 --record</span> <b>change the image of nginx to 1.9.1</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl rollout status deployment/nginx-deploy </span><span style="font-family: inherit;"><b>returns rollout status of nginx-deploy</b></span></div><div><span style="font-family: inherit;"><b><br /></b></span></div><div><span style="font-family: courier;">kubectl rollout history deployment/nginx-deploy</span> <b><span style="font-family: inherit;">returns rollout history of nginx-deploy</span></b></div><div><b><span style="font-family: inherit;"><br /></span></b></div><div><span style="font-family: courier;">kubectl rollout undo deployment/nginx-deploy</span> <b>undo the changes </b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl rollout status deployment/nginx-deploy</span> <b>returns rollout status of nginx-deploy</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl describe deploy nginx-deploy | grep -i image</span> <b>returns image details of nginx-deploy</b></div><div><b><br /></b></div><div><span style="font-family: courier;">kubectl edit deployment redis-deployment</span><b> edit the deployment configurations of "</b><b>redis-deployment"</b></div></div><div><br /></div></div>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-87125162770417859072023-06-01T07:04:00.004-07:002023-06-01T07:04:58.262-07:00Enable RabbitMQ plugins<p>In RabbitMQ command prompt, use following commands to enable plugins.</p><p><span style="font-family: courier;">rabbitmq-plugins enable rabbitmq_management</span></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-86156967427544101822023-06-01T06:58:00.008-07:002023-06-01T07:01:49.395-07:00Docker Commands-Updated<p></p><p style="text-align: left;"></p><ul style="text-align: left;"><li><span style="font-family: courier;">docker -v </span><b> returns docker version </b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker login </span><b>login to docker hub using command line</b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker pull hello-world</span> <b>retrieve hello-world docker image from docker hub</b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker run hello-world</span> <b>execute hello-world docker image</b></li></ul><p style="text-align: left;"></p><ul style="text-align: left;"><li><span style="font-family: courier;">docker ps -a</span> <b>list all processes in docker</b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker rmi hello-world --force</span><b> delete hello-world image from docker </b><b>forcefully </b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker rm container_id --force </span><b>delete container from docker forcefully </b></li></ul><p></p><ul style="text-align: left;"><li><span style="font-family: courier;">docker run -d nginx </span><b>run nginx server in background</b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker ps</span> <b>list running processes in docker</b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker container inspect container_id</span> <b>get the all information about docker container </b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker run -d -p 3600:80 --name sujith-nginx nginx</span> <b>port forwarding with docker images execution </b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker exec -it container_d redis redis-cli</span> <b>access redis-cli after docker image execution</b></li></ul><ul style="text-align: left;"><ul><li><span style="font-family: courier;">set myvalue 5 </span><b>set value redis</b></li></ul></ul><ul style="text-align: left;"><ul><li><span style="font-family: courier;">get myvalue </span><b>retrieve value</b></li></ul></ul><p style="text-align: left;"></p><ul style="text-align: left;"><li><span style="font-family: courier;">docker run -it ubuntu bash</span> <b>run ubuntu with bash access in docker</b></li></ul><ul style="text-align: left;"><ul><li><span style="font-family: courier;">apt-get install git tree -y</span> <b>install git inside ubuntu</b></li></ul></ul><ul style="text-align: left;"><ul><li><span style="font-family: courier;">ctrl + p + q</span><b> exit to run git in background </b></li></ul></ul><p></p><ul style="text-align: left;"><li><span style="font-family: courier;">docker container commit --author "sujith" -m "my custom image" running_container_id my_ubuntu_git_image</span> <b>create image using running git installed ubuntu container</b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker docker tag my_ubuntu_git_image sujithdc/my_ubuntu_git_image</span> <b>tagging docker image to push to docker hub</b></li></ul><ul style="text-align: left;"><li><span style="font-family: courier;">docker push sujithdc/my_ubuntu_image</span> <b>push image to docker hub</b></li></ul><p></p><p></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-42161975289927169242023-05-11T02:26:00.010-07:002023-05-11T02:27:21.593-07:00fatal: Authentication failed git resolution<p> If you have changed your certificate of your git repository, you will receive the following error message.</p><p><span style="font-family: courier;">fatal: Authentication failed for for 'https://bitbucket.*****/***/usermgt*.git/'</span></p><p>You can follow following steps to resolve the issue.</p><p>1. Retrieve the remote URL</p><p><span class="ui-provider hb b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak" dir="ltr"><span style="font-family: courier;">git remote -v</span></span></p><p>2. Remove the remote URL</p><p><span class="ui-provider hb b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak" dir="ltr"><span style="font-family: courier;">git remote rm origin</span></span></p><p>3. Add URL as new remote URL</p><p><span style="font-family: courier;"><span class="ui-provider hb b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak" dir="ltr">git remote add origin </span>https://bitbucket.*****/***/usermgt*.git</span></p><p>4. Make changes and push</p><p><span class="ui-provider hb b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak" dir="ltr"><span style="font-family: courier;">git push origin master</span></span></p><p><span class="ui-provider hb b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak" dir="ltr"><span style="font-family: courier;"><br /></span></span></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-91981960319051148662022-04-22T04:42:00.003-07:002022-11-17T00:29:50.840-08:00git commands<p>List of important commands for git CLI users</p><p></p><p style="text-align: left;"></p><ul style="text-align: left;"><li>git clone - clone project to local machine</li></ul><ul style="text-align: left;"><li>git status<span style="white-space: pre;"> </span>- check current status </li></ul><ul style="text-align: left;"><li>git add ./filename - add new changes locally</li></ul><ul style="text-align: left;"><li>git commit -m message - commit new changes into bitbucket</li></ul><ul style="text-align: left;"><li>git push - will send changes into bitbucket</li></ul><ul style="text-align: left;"><li>git pull - get updates from bitbucket to local repository</li></ul><ul style="text-align: left;"><li>git branch - view current working branch</li></ul><ul style="text-align: left;"><li>git branch dev - create a new branch called dev</li></ul><ul style="text-align: left;"><li>git checkout dev - switch into dev from current branch</li></ul><ul style="text-align: left;"><li>git push --set-upstream origin dev - push changes to dev branch</li></ul><p></p><ul style="text-align: left;"><li>git remote -v - find remote repository url</li></ul><p></p><ul style="text-align: left;"><li>git remote set-url origin https://github.com/suji/TestApp.git - change remote repository url to a new one</li><li>git merge --abort -abort current merge command</li><li>git remote rm origin -remove origin url of repository</li></ul><p></p><p></p><p></p><p></p><p><br /></p><p>Create a new repository on the command line</p><p></p><p style="text-align: left;"></p><ul style="text-align: left;"><li>echo "# TestApp" >> README.md</li></ul><ul style="text-align: left;"><li>git init</li></ul><ul style="text-align: left;"><li>git add README.md</li></ul><ul style="text-align: left;"><li>git commit -m "first commit"</li></ul><ul style="text-align: left;"><li>git remote add origin https://github.com/sujith/TestApp.git</li></ul><ul style="text-align: left;"><li>git push -u origin master</li></ul><p></p><p></p><p><br /></p><p>Push an existing repository from the command line</p><p></p><p style="text-align: left;"></p><ul style="text-align: left;"><li>git remote add origin https://github.com/sujith/TestApp.git</li></ul><ul style="text-align: left;"><li>git push -u origin master</li></ul><p></p><p></p><p><br /></p><p>When you add new file(which has already in the git repository) to git ignore file, run below command to ignore it. </p><p></p><p style="text-align: left;"></p><p style="text-align: left;"></p><ul style="text-align: left;"><li>git rm -r --cached . </li></ul><ul style="text-align: left;"><li>git add .</li></ul><ul style="text-align: left;"><li>git commit -m 'removing ignored files'</li></ul><div><br /></div><p></p><p></p><p>Configure git for the first time</p><p></p><p style="text-align: left;"></p><ul style="text-align: left;"><li>git config --global user.name "Sujith Delpachithra"</li></ul><ul style="text-align: left;"><li>git config --global user.email "sujith@g**.lk"</li></ul><p></p><p></p><p><br /></p><p>If your code is already tracked by git then set this repository as your "origin" to push.</p><p></p><p style="text-align: left;"></p><ul style="text-align: left;"><li>cd existing-project</li></ul><ul style="text-align: left;"><li>git remote add origin http://bitbucket.mobitel.lk/suji/testapp.git</li></ul><ul style="text-align: left;"><li>git push -u origin --all</li></ul><ul style="text-align: left;"><li>git push origin --tags</li></ul><p></p><p></p><p><br /></p><p>You can use the git cherry-pick command to merge one branch to another.</p><p></p><ul style="text-align: left;"><li>git cherry-pick d4d8e7c</li></ul><p></p><p>(Replace d4d8e7c with relevant commit id you need to merge from another branch to this branch)</p><p><br /></p><p>You can revert to previous commit.</p><p></p><p style="text-align: left;"></p><ul style="text-align: left;"><li>git reset --hard <commit_id></li></ul><ul style="text-align: left;"><li>git push -f origin staging</li></ul><p></p><p></p><p><br /></p><p>Let's say you want to merge local development branch into local staging branch.</p><p>Then first you need to checkout stating branch with this command.</p><p></p><ul style="text-align: left;"><li>git checkout staging</li></ul><p></p><p>Then you can do merging with this command.</p><p></p><ul style="text-align: left;"><li>git merge development</li></ul><p></p><p><br /></p><p>How to merge development branch changes to staging branch.</p><p>1. First checkout to staging branch</p><p>2. Then execute below command</p><p></p><ul style="text-align: left;"><li>git merge development</li></ul><p></p><div><br /></div>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-68858811299193860152022-04-21T05:13:00.004-07:002022-04-21T05:13:50.646-07:00Sending mails/ sms from Linux server<p>You have to configure mail server in Linux server. Then you can use following command to send mails.</p><p><span style="font-family: inherit;">For <span style="background-color: white; color: #242424; font-size: 14px;">mail -</span></span></p><p><span style="background-color: white; color: #242424; font-size: 14px;"><span style="font-family: courier;">mail -s "subject" recipients_emails < mail body</span></span></p><p><span style="background-color: white; color: #242424; font-size: 14px;"><span style="font-family: inherit;">For SMS -</span></span></p><p><span style="background-color: white; color: #242424; font-family: courier; font-size: 14px;">mail -s "subject" number@your_email_domain < mail body</span></p><p><span style="background-color: white; color: #242424; font-family: courier; font-size: 14px;"><br /></span></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-53481019837139521292022-04-21T05:00:00.004-07:002022-04-21T05:00:48.536-07:00Schell script to restart JAVA apps<p>#!/bin/bash</p><p>ps -ef |grep "java -jar" > /apps/sujith/apps</p><p>x=$(cat /apps/sujith/apps |grep "SMS_App.jar" |wc -l)</p><p>echo $x</p><p> if [ $x = 0 ]</p><p> then</p><p> date</p><p> echo " Starting ......Please check logs !! "</p><p> echo ""</p><p> cd /apps/sujith/sms</p><p> nohup java -jar -Xms32m -Xmx128m SMS_App.jar 2>> SMS_App.err &</p><p> elif [ $x = 1 ]</p><p> then</p><p> date</p><p> echo "STOPPING "</p><p> cat /apps/sujith/apps |grep "SMS_App.jar" | awk -F " " '{print $2}' | xargs kill -9</p><p> echo "STOPPED "</p><p> date</p><p> echo "STARTING"</p><p> cd /apps/sujith/sms</p><p> nohup java -jar -Xms32m -Xmx128m SMS_App.jar 2>>SMS_App.err &</p><p> else</p><p> echo "SMS App"</p><p> fi</p><div><br /></div>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-60521280195517612562022-04-18T00:26:00.005-07:002022-04-18T00:26:59.002-07:00sample docker file for JAVA application<p> You can add following Dockerfile to JAVA docker image.</p><div style="text-align: left;">#Use open JDK 8 image as the base image<br /><span style="font-family: courier;">FROM openjdk:8</span></div><div style="text-align: left;"><br />#Create a new app directory for my application files (Inside image file system)<br /><span style="font-family: courier;">RUN mkdir /app</span></div><div style="text-align: left;"><br />#Set the directory for excuting future commands<br /><span style="font-family: courier;">WORKDIR /app</span></div><div style="text-align: left;"><br />#Copy my application files from host machine into image file system<br /><span style="font-family: courier;">COPY target/docker-helloworld-1.0-SNAPSHOT.jar app.jar</span></div><div style="text-align: left;"><br />#Run jar file<br /><span style="font-family: courier;">ENTRYPOINT ["java","-jar","app.jar"]</span></div><div style="text-align: left;"><span style="font-family: courier;">#CMD java -jar app.jar</span></div><div style="text-align: left;"><br /></div>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-65915565647079824282022-04-18T00:17:00.005-07:002022-04-18T01:31:42.621-07:00docker commands<p></p><ul style="text-align: left;"><li><span style="font-family: courier;">docker -version</span></li></ul><p></p><p>checking current installed docker version</p><p></p><ul style="text-align: left;"><li><span style="font-family: courier;">docker container run hello-world</span></li></ul><p></p><p>run hello-world docker image. if image is not available in local repository, above command will download the image from docker-hub</p><p></p><ul style="text-align: left;"><li><span style="font-family: courier;">docker run -it ubuntu bash</span></li></ul><div>run ubuntu container in docker.</div><div><ul style="text-align: left;"><li><span style="font-family: courier;">docker ps</span></li></ul></div><div>list running docker container</div><div><ul style="text-align: left;"><li><span style="font-family: courier;">docker image build -t hello-world:1.0 .</span></li></ul></div><div>use above command for buid a docker image. (here . means Dockerfile contains in the current directory)<br /></div><div><ul style="text-align: left;"><li><span style="font-family: courier;">docker container run hello-world:1.0</span></li></ul></div><div>use below command for run above docker image.</div><div><ul style="text-align: left;"><li>docker image ls</li></ul></div><div>list images in local repository</div><div><br /></div><p></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-28354887884662536492022-03-23T23:26:00.000-07:002022-03-23T23:26:37.094-07:00Shutdown Spring Boot Command Line Application<p>You can use <span style="font-family: courier;">ConfigurableApplicationContext </span><span style="font-family: inherit;">to shutdown/closes all resources used by</span><span style="font-family: inherit;"> application as follows.</span></p><p><span style="font-family: courier;"> public static void main(String[] args) {</span></p><p><span style="font-family: courier;"> ConfigurableApplicationContext ctx=SpringApplication.run(Application.class, args);</span></p><p><span style="font-family: courier;"> ctx.close();</span></p><p><span style="font-family: courier;"> } </span></p><p><span style="font-family: courier;"> @Bean</span></p><p><span style="font-family: courier;"> public CommandLineRunner commandLineRunner(RestTemplate restTemplate) {</span></p><p><span style="font-family: courier;"> return args -> {</span></p><p><span style="font-family: courier;"><span style="white-space: pre;"> </span>}</span></p><p><span style="font-family: courier;"> }</span></p><p><br /></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-5574972127694856452022-03-14T20:03:00.001-07:002022-03-14T20:03:37.332-07:00Remove the <return> tag from SOAP response in JAVA<p> Following JAVA annotation can be used to avoid <return> tag from SOAP web service response.</p><p><span style="font-family: courier;">@WebService(serviceName = "Operations")</span></p><p><span style="font-family: courier;">public class Service {</span></p><p><span style="font-family: courier;"> @WebMethod(operationName = "</span><span style="font-family: courier;">processUser</span><span style="font-family: courier;">")</span></p><p><b><span style="font-family: courier;"> @SOAPBinding(parameterStyle=ParameterStyle.BARE)</span></b></p><p><span style="font-family: courier;"> public Result processUser(@WebParam(name = "userName")String userName) {</span></p><p><span style="font-family: courier;"><span> </span><span> </span>Result result = new Result();</span></p><p><span style="font-family: courier;"> result.setResultCode("1");</span></p><p><span style="font-family: courier;"></span></p><p><span style="font-family: courier;"> result.setResultDesc("success");</span></p><p><span style="font-family: courier;"><span> </span><span> </span>return </span><span style="font-family: courier;">result;</span></p><p><span style="font-family: courier;"><span> </span>}</span></p><p><span style="font-family: courier;">}</span></p><p><b>ParameterStyle.BARE </b>will return SOAP response with your defined object attributes.</p><p><br /></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-7771973303972935062021-11-23T03:11:00.003-08:002021-11-23T03:11:20.318-08:00List directories with sizes in Linux<p><span style="font-family: courier;"><span style="background-color: white; color: #242424; font-size: 14px;">du -sh *</span></span></p><p>Above command can be used to grep directory sizes in Linux. Go to required directory and execute above command.</p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-8770413065423357422021-08-26T23:33:00.003-07:002021-08-26T23:33:45.046-07:00JSCH "Algorithm negotiation fail" error<p>It was received the following error when creating SSH session using JSCH client. I was able to resolve this after updating JSCH version to 0.1.54.</p><p></p><blockquote><p>com.jcraft.jsch.JSchException: Algorithm negotiation fail</p><p> at com.jcraft.jsch.Session.receive_kexinit(Session.java:583)</p><p> at com.jcraft.jsch.Session.connect(Session.java:320)</p><p> at com.jcraft.jsch.Session.connect(Session.java:183)</p></blockquote><div><div></div></div><blockquote><div><div><!-- https://mvnrepository.com/artifact/com.jcraft/jsch --></div><div><dependency></div><div> <groupId>com.jcraft</groupId></div><div> <artifactId>jsch</artifactId></div><div> <version>0.1.54</version></div><div></dependency></div></div><div></div></blockquote><div><br /></div>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-79406692808353417372021-07-17T07:45:00.004-07:002021-07-17T07:45:58.783-07:00Kill processes created under specific user in Linux<p> You can use following commands to kill processes created under specific user in Linux.</p><p class="xmsonormal"><o:p></o:p></p><p><span style="font-family: courier;">for k in `ps -ef | grep usr01| grep ssh | awk '{print
$2}'` ; do kill -9 $k ; done</span></p><p>Here, it is killing ssh sessions created by usr01 user.</p><p><br /></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-47362874195583272942021-04-09T10:13:00.004-07:002021-04-09T10:13:28.962-07:00Edit XSD files to resolve AXIS web service invalid element error<p> When executing webservices using AXIS, you can receive following error due to invalid elements.</p><p></p><p class="MsoNormal">
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Invalid
element in com.mobitel.axis.AdjustmentResult -
AdjustmentSerialNo<o:p></o:p></p><p class="MsoNormal">You can edit XSD file for this WSDL and add AdjustmentSerialNo element to AdjustmentResult element to resolve this. You have to download XSD files and generate webservice clients.</p><p class="MsoNormal"><br /></p><br /><p></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-19678862344654089422021-03-08T06:57:00.004-08:002021-03-08T06:58:41.708-08:00Retrieve few minutes older records from SQL in Oracle<p>You can use following SQL syntax to retrieve data in 5 minute interval in Oracle database. </p><p><span style="font-family: courier;">select * FROM test_table where added_time <= systimestamp - numtodsinterval(5,'MINUTE')</span></p><p><span style="font-family: inherit;">Above SQL returns values which are older than 5 minutes </span> than system time <span style="font-family: inherit;">in added_time column.</span></p><p><span style="font-family: inherit;"><br /></span></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-20363145107829752412021-01-19T07:34:00.003-08:002021-08-26T23:34:41.877-07:00Insert Timestamp to Oracle Timestamp in JAVA<p> You can use following formatting to insert JAVA timestamp to Oracle Timestamp.</p><p><span style="font-family: courier;">insert into test_table(added_time) values(TO_TIMESTAMP('2021-01-18 17:43:42.000000000', 'YYYY-MM-DD HH24:MI:SS.FF'))</span></p><p><span style="font-family: courier;"><br /></span></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-4893642605672263082021-01-19T07:29:00.004-08:002021-01-19T07:29:30.379-08:00Oracle Timestamp Issue<p><span style="font-family: inherit;">When querying Oracle Timestamp to JAVA Timestamp following error can be occurred. </span></p><h4 style="text-align: left;"><span style="background-color: white; box-sizing: border-box; color: #4d4d4d; font-size: 16px; outline: 0px; overflow-wrap: break-word;"><span style="box-sizing: border-box; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;"><span style="box-sizing: border-box; font-family: inherit; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;"><b>java.lang.ClassCastException: oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp</b></span></span></span></h4><p><span style="background-color: white; box-sizing: border-box; color: #4d4d4d; font-size: 16px; outline: 0px; overflow-wrap: break-word;"><span style="box-sizing: border-box; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;"><span style="box-sizing: border-box; font-family: inherit; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;">This error can resolve using following two options.</span></span></span></p><p style="background-color: white; box-sizing: border-box; color: #4d4d4d; font-size: 16px; line-height: 26px !important; margin: 0px 0px 16px; outline: 0px; overflow-wrap: break-word; overflow: auto hidden; padding: 0px;"><span style="box-sizing: border-box; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;"><span style="font-family: inherit;">1. Add JVM startup parameters. </span><span style="font-family: courier;">-Doracle.jdbc.J2EE13Compliant=true</span><span style="font-family: inherit;"> in the application</span></span></p><p><span style="background-color: white; box-sizing: border-box; color: #4d4d4d; font-size: 16px; font-weight: 700; outline: 0px; overflow-wrap: break-word;"><span style="box-sizing: border-box; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;"><span style="box-sizing: border-box; font-family: inherit; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;"></span></span></span></p><p style="background-color: white; box-sizing: border-box; color: #4d4d4d; font-size: 16px; line-height: 26px !important; margin: 0px 0px 16px; outline: 0px; overflow-wrap: break-word; overflow: auto hidden; padding: 0px;"><span style="box-sizing: border-box; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;"><span style="font-family: inherit;">2. Add system properties in the application. </span><span style="font-family: courier;">System.getProperties().setProperty("oracle.jdbc.J2EE13Compliant", "true")</span></span></p><p style="background-color: white; box-sizing: border-box; color: #4d4d4d; font-size: 16px; line-height: 26px !important; margin: 0px 0px 16px; outline: 0px; overflow-wrap: break-word; overflow: auto hidden; padding: 0px;"><span style="box-sizing: border-box; font-family: inherit; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;">Reference site</span></p><p style="background-color: white; box-sizing: border-box; line-height: 26px !important; margin: 0px 0px 16px; outline: 0px; overflow-wrap: break-word; overflow: auto hidden; padding: 0px;"><span style="box-sizing: border-box; color: #4d4d4d; font-family: inherit; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;">https://docs.oracle.com/cd/B28359_01/java.111/b31224/datacc.htm</span></p><p style="background-color: white; box-sizing: border-box; line-height: 26px !important; margin: 0px 0px 16px; outline: 0px; overflow-wrap: break-word; overflow: auto hidden; padding: 0px;"><span style="box-sizing: border-box; color: #4d4d4d; font-family: -apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun; outline: 0px; overflow-wrap: break-word; vertical-align: inherit;"><br /></span></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-816874958446580862021-01-05T02:18:00.007-08:002021-01-05T02:18:58.309-08:00Informix query optimizer<p><span style="font-family: inherit;"> </span></p><p class="MsoNormal"><b><span style="font-family: inherit;">The Informix Query Optimizer</span></b></p>
<p class="MsoNormal"><span style="font-family: inherit;">• The query optimizer attempts to determine the most
efficient way to execute a SQL statement<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><span style="mso-spacerun: yes;"> </span>• Examines every
possible method to implement the query and selects the least costly method<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;">• It is Dynamic, so when data changes the same SQL can
select a better path<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;"><br /></span></p><p class="MsoNormal"></p><p class="MsoNormal"><span style="font-family: inherit;"><b>How Optimizes the SQL statement to determine the best
access method </b><u><o:p></o:p></u></span></p>
<p class="MsoNormal"><span style="font-family: inherit;">– Which table to read first…. <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;">– Which index to use first… <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;">– Which filter to use first…<o:p></o:p></span></p>
<p class="MsoNormal"><o:p><span style="font-family: inherit;"> </span></o:p></p>
<p class="MsoNormal"><b><span style="font-family: inherit;">How to Turn ON Query Explain? To See the SQL Optimizer
Query Plan</span></b></p>
<p class="MsoNormal"><span style="font-family: inherit;">After executes below queries with “SET EXPLAIN” it is
creates a output file called “SQL_EXPLAIN.OUT”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><b>Method#1</b><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><span style="mso-tab-count: 1;"> </span>SET
EXPLAIN ON - <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><span style="mso-tab-count: 2;"> </span>Display
the query plan that optimizer chooses, then execute the query.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><span style="mso-tab-count: 2;"> </span>Example:
<o:p></o:p></span></p>
<p class="MsoNormal"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><span style="font-family: inherit;"><span style="mso-tab-count: 3;"> </span>set
explain on;<o:p></o:p></span></i></b></p>
<p class="MsoNormal"><span style="font-family: inherit;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;"><span style="mso-tab-count: 2;"> </span><span style="mso-tab-count: 1;"> </span>select cust_name,cust_addrs from
customer where cust_code=”C001”</i></b>;<span style="mso-tab-count: 1;"> </span><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><b>Method#2</b><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><span style="mso-tab-count: 1;"> </span>SET
EXPLAIN ON FILE TO [“path/to/filename”]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><span style="mso-tab-count: 2;"> </span>Save
the query plan into a specific file also execute the query.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: .5in; text-indent: .5in;"><span style="font-family: inherit;">Can useful when programming
unit testing.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><b>Method#3</b><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><span style="mso-tab-count: 1;"> </span>SET
EXPLAIN ON AVOID_EXECUTE <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: inherit;"><span style="mso-tab-count: 2;"> </span>Display
the query plan that optimizer chooses, but do not execute the query.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: .5in; text-indent: .5in;"><span style="font-family: inherit;">Can useful when a
query takes hours to run/for time consuming queries.</span></p><p class="MsoNormal" style="margin-left: .5in; text-indent: .5in;"><span style="font-family: inherit;"><br /></span></p><p class="MsoNormal"><span style="font-family: inherit;"><b>“SQL_EXPLAIN.OUT” file results explanation</b></span></p><p></p><p class="MsoNormal"><span style="font-family: inherit;">A. Show SQL/SELECT statement.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;">B. Query cost<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;">C. Number of Rows Expected to return<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;">D. Order to access tables during execution.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;">E. Access Plan: <o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;"> SEQUENTIAL
Scan - read all rows in sequence<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;"> INDEX
PATH - Scan 1 or more indexes<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;"> AUTO
INDEX PATH: Optimizer suggest to create an indexes.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;">F. Query Statistics <o:p></o:p></span></p><p class="MsoNormal" style="text-indent: .5in;"><span style="font-family: inherit;">Shows tables map, estimated row
count and estimated query costs step by step.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: inherit;"> This
will helps to find out in which part of the query cost is high.<o:p></o:p></span></p><p class="MsoNormal" style="margin-left: .5in; text-indent: .5in;">
</p><p class="MsoNormal"><span style="font-family: inherit;"> So can
change the query based on results output.</span><o:p></o:p></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0tag:blogger.com,1999:blog-4568934403085048179.post-332783238891261942020-10-20T08:54:00.005-07:002020-10-20T08:54:48.382-07:00Retrieve few minutes older records from SQL in Informix<p>You can use following SQL to retrieve records older than 15 minutes in Informix. init_time is in datetime format. </p><p><span style="font-family: courier;">select * from table_name where init_time > (current - 15 units minute)</span></p><p><br /></p>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com1tag:blogger.com,1999:blog-4568934403085048179.post-41740705442018636292020-08-11T19:56:00.004-07:002020-08-11T19:56:32.013-07:00Search files in sub directories in LinuxFollowing command can use to list files <b>staring with 1234 </b>in all sub directories. <div><br /></div><div><span style="font-family: courier;">ls –R | grep 1234*</span></div><div><br /></div>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com1tag:blogger.com,1999:blog-4568934403085048179.post-60426524910802749832020-07-27T20:19:00.002-07:002020-07-27T20:20:07.732-07:00List absolute paths for files in LinuxFollowing Linux command can be used to list absolute file paths.<br />
<span style="color: #242729; font-family: "courier new" , "courier" , monospace; font-size: x-small; font-style: inherit; font-weight: inherit; white-space: inherit;"><br /></span>
<span style="color: #242729; font-family: "courier new" , "courier" , monospace; font-style: inherit; font-weight: inherit; white-space: inherit;">ls -d /apps/*</span>Sujith Delpachithrahttp://www.blogger.com/profile/08076836689428250433noreply@blogger.com0