HOME BLOG

Tips for deploying apps with Kubernetes

Posted on: November 13th, 2021 by Olu No Comments

Hi folks,

In this post i go over a few tips to keep in mind when deploying applications with Kubernetes.

1. After updating a Kubernetes deployment, double-check to make sure the deployment is up-to-date. You can run command

kubectl get deployment

There will be a column UP-TO-DATE.  Make sure it is 1. If it isn’t, then check the state of the deployment rollout. If there is any issue with rolling out your deployment, you can scale down and then scale up replicas to update the pods.

2. Make sure your cluster has enough resources (memory, CPU) for your application’s needs. E.g. If your pod requests more memory than the cluster has available, Kubernetes will not allow it run.

That’s all for now. Till next time, happy software development.

How to search and replace unprintable character with Vim

Posted on: October 14th, 2021 by Olu No Comments

Hi folks,

In this post I talk about how to search and replace unprintable character with Vim. I once found myself in a situation where some code wouldn’t run in my file due to an unknown character. It turned out the character wasn’t visible, so I had to find a way to remove it. If you find yourself in a similar situation here’s what to do:

First try to set encoding type and see if that works.

:set encoding=utf-8

If that doesn’t work, you can place the cursor on the unprintable character and press keys ga. This will show the decimal/hexadecimal/octadecimal code for the character. You can then replace it with command:

:%s/\%xYY/yournewchar/g

Or for multibyte character use:

:%s/\%uYYYY/yournewchar/g

See the following for details

:help character-class

 

Reference

How to search and replace an unprintable character. Stackoverflow. https://stackoverflow.com/questions/2798398/how-to-search-and-replace-an-unprintable-character/2801132

How to view Kubernetes resources of a specific API version

Posted on: September 20th, 2021 by Olu No Comments

Hi folks,

Here’s a quick tip on how to view Kubernetes resource of a specific API version. For example, there are different types of Network Policy resources that Kubernetes supports.

There’s the default network policy which has kind NetworkPolicy under apiVersion networking.k8s.io/v1.
Then let’s say there’s another resource of kind NetworkPolicy under apiVersion projectcalico.org/v3.

How do you view all network resources under apiVersion projectcalico.org/v3?

Here’s the command for it:

kubectl get networkpolicy.v3.projectcalico.org

That’s all for now. Happy Software Development.

How to run a one-off job from a Kubernetes Cronjob

Posted on: September 7th, 2021 by Olu No Comments

Hi folks,

In this post I talk about how to manually run a job from a Kubernetes cronjob.

Assume the cronjob is called mycronjob, you can use the following command:

 

kubectl create job --from=crojob/mycronjob name-of-job

That’s all for now. Happy software development.

How to prevent web application from revealing git repository details

Posted on: August 21st, 2021 by Olu No Comments

Hi folks,

In this post I will discuss a security tip. If your web application uses Git for version control, then there would usually be a .git folder in the project’s root folder. Here’s a quick way to prevent users from accessing details under your .git folder from a web browser.

Implement a 404 redirect for any request starting with /.git.

If you use Apache web server and your project users a .htaccess file, you can do this by adding a simple rule to your .htaccess file as follows:

RedirectMatch 404 /\.git

That’s all for now. Happy software development.

How to get process id of last executed background process in Shell script

Posted on: August 10th, 2021 by Olu No Comments

Hi folks,

In this short post I will describe how to get the process id of the last process that was executed in the background.

You do that using the symbol $!

E.g. If you run the commands:

date &
echo $!

you will get an id like 12345 corresponding of the process id for the date command you ran in the background previously.

The process id of the last run background process could be very useful if you want to do things like killing the process when a certain condition is meant. For example, when deploying multicontainer pods in Kubernetes using the sidecar pattern, you may want to terminate the sidecar container once the main container’s process finishes. One way to do this is in the sidecar is to start the sidecar process in the background, fetch its process id, wait for a trigger file which will be written by main container to signal process completion, then kill the sidecar process once the trigger file is found.

See the article How to terminate a side-car container in Kubernetes Job [1] for details.

That’s all for now. Happy software development.

 

Reference

1. How to terminate a side-car container in Kubernetes Job https://cotton-ori.medium.com/how-to-terminate-a-side-car-container-in-kubernetes-job-2468f435ca99

2. Does $! mean something in shell scripting. Stackoverflow. https://stackoverflow.com/questions/18462916/does-mean-something-in-shell-scripting

How to add Search feature to your Dango app with Haystack and Solr

Posted on: August 4th, 2021 by Olu No Comments

Hi folks,

In this post I talk briefly about how you can add search functionality to your Django app. Why add search platforms like Solr, Elasticsearch,e tc. to your app? Because it makes it easier for users to find relevant information, especially when it may be resource-intensive to perform those searches with your database alone. There’s an interesting article on this topic: Solr and RDBMS: Designing your application for the best of both. https://lucidworks.com/post/solr-and-rdbms-the-basics-of-designing-your-application-for-the-best-of-both/. There are several search tools you can use including Solr, Sphinx, etc. let’s assume you want to use Solr.

There’s a modular library you can use called Haystack (https://django-haystack.readthedocs.io/en/master/toc.html). Haystack supports several search tools, including Solr, Elasticsearch, etc.

If you want to use Haystack with Solr, you’ll need to have Solr running first. You can install Solr on different platforms. Haystack config details are found  at https://django-haystack.readthedocs.io/en/master/tutorial.html#installation.

Details about installing Solr for use with Haystack can be found here https://django-haystack.readthedocs.io/en/master/installing_search_engines.html.

When you install and start Solr, you would usually want to create something called a core. You perform indexing in that core and perform your searches against the core. Multiple cores can be created on a single Solr instance. When referencing Solr in an application, you would usually use a url like http://127.0.0.1/solr/<yourcore>. Haystack provides management command for interacting building search index and updating search index. You can install Solr using a docker container. See https://hub.docker.com/r/geerlingguy/solr/.

That’s all for now. Till next time, happy software development.

How to view stack trace on app crash when running Django management commands

Posted on: July 19th, 2021 by Olu No Comments

Hi folks,

In this post I describe how to view stack trace on app crash when running Django management commands. When using older versions of Django, if you run a management command and it crashes, you may notice that only the error message is displayed. It would be helpful to see a stack trace as well to facilitate debugging. Thankfully, it’s easy to enable stack trace display.

To view stack trace on error when running Django management command, use the –traceback option. E.g.

 

python manage.py some-command --traceback

 

That’s all for now. Happy software development.

What is Pandas and Why Should You Care About It?

Posted on: July 4th, 2021 by Olu No Comments

Hi folks,

In this post I’ll talk about Pandas.

First, what is Pandas?

Pandas is a software library written in Python programming language. It is used for data manipulation and analysis. It gives you data structures for manipulating numerical tables and time series.

When should you consider learning and using Pandas?

    • If you have to stitch data together from different sources
    • If you need to read data from one or more sources and enrich it
    • If you need to perform statistics on data e.g. find means, counts, etc.
    • If you need to perform data transformations.

Pandas provides several powerful constructs that allow you manipulate data easily.

You can read data into Pandas from many sources, e.g. csv files and MS Excel files. You can also read data into Pandas dataframes from arbitrary sources if the data is available as a list or dictionary.

You can filter and group data, you can also transform data among other things.

When you combine Pandas with a plotting  library like Matplotlib you can create great graphs and charts to visualize data easily.

You can learn more about Pandas by visiting the Pandas website https://pandas.pydata.org/. For some general information no it, visit its Wikipedia page https://en.wikipedia.org/wiki/Pandas_(software).

That’s all for now. Happy software development.

Black – the code formatter

Posted on: May 25th, 2021 by Olu No Comments

Hi folks,

In this post I’ll talk about a very interesting tool called Black. Once upon a time, I was tasked with writing Python software with a few other developers. We came from different backgrounds and thus had very different styles of writing code. There was a broad mix of code writing styles and believe me, the code was a thing to behold. But we decided to just play along and let everyone be and allow “diversity” of code styles. It wasn’t very pretty but we lived with it.

Some months later I found myself reading through the codebase of a Python project and discovered a very interesting tool called Black. The software is described by its authors as The Uncompromising Code Formatter. Once I discovered what it does I realized that this is a tool that would have solved the problem I described earlier. Black formats Python code so that it looks neat consistent. That way, developers don’t have to bicker over poor code format. This also allows developers to focus more on content and less on formatting.

I highly recommend using Black as a code formatter if working on Python in a team setting. You can install Black from PyPi using pip. Click here to go to the project’s Github home page.

That’s all for now. Happy software development.