How Do You Write a BubbleSort Algorithm in Python That Runs in O(n) in a Best Case Scenario?

Problem scenario
You want to use BubbleSort in Python that runs in O(n) time when the list to be sorted is already in perfect order.  How do you write such a program?

Solution
Use this code for BubbleSort with a refinement:

def refinedBubbleSort(coollist):
    needtoswap = True
    x = len(coollist)-1   # x is now the index value of last item in list
    while x > 0 and needtoswap:
       needtoswap = False
       for i in range(x):  # start with leftmost number and iterate to the xth position one space at a time
           if coollist[i] > coollist[i+1]:   # swap if left item in pair is greater than right item
               needtoswap = True
               coollist[i],coollist[i+1] = coollist[i+1],coollist[i]
       x = x-1  # Go through the list from rightmost item until the leftmost item
coollist = [1,2,3,4,5,6,7,8,9,10]
refinedBubbleSort(coollist)
print(coollist)  

How Do You Install Sysdig in an Existing Debian-Based Docker Container?

Problem scenario
You want to monitor Docker containers.  Therefore you want to install Sysdig to try it out.  How do you install Sysdig in a pre-existing Docker container?

Solution
Run these three commands:
apt-get -y update
apt-get -y install curl
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | bash

How Do You Get a DNS Server That Was Working to Work Again?

Problem scenario
Your DNS server does not seem to be working any more.  What should you do?

Solution
1.  Can you ping it? 
2.  Log into it.  Run these commands to ensure that there is activity on a port:

sudo netstat -anlp | grep :53
nmap -Pn 127.0.0.1

If there is no activity, start the service with this command:
sudo systemctl start named.service

What Do You Need to Do to Get a RHEL Server to Be a DNS Server?

Problem scenario
You have a RHEL server in AWS.  You want it to be a DNS server.  What do you do?

Solution
For security reasons, you should have the network that this DNS server will serve be behind a firewall.  Following a short Question and Answer guide like this is fine for testing and learning.  However, denial of service attacks are more possible when a primary DNS server engages in recursive look ups (page 857 of A Practical Guide to Fedora and RedHat Enterprise Linux). Recursive queries involve a second query to a different DNS sever.  A non-recursive DNS query is called iterative.  The BIND service should run in a chroot jail as a precautionary measure for security (page 883 of A Practical Guide to Fedora and RedHat Enterprise Linux).

1. Run this:  sudo yum -y install bind bind-utils

2. Run these commands:

    sudo systemctl enable named.service
    sudo systemctl start named.service

A List of Kubernetes Books

Some of these items are books, practice exams or DVDs related to Kubernetes. This list was updated on 4/5/20.

Amazon EKS: User Guide
Building Enterprise JavaScript Applications: Learn to build and deploy robust JavaScript applications using Cucumber, Mocha, Jenkins, Docker, and Kubernetes
Building Microservice Systems with Docker and Kubernetes - Training DVD
Certified Kubernetes Application Developer (CKAD) Complete Video Learning Certification Exam Set (DVD)
Cloud Native DevOps with Kubernetes: Building, Deploying, and Scaling Modern Applications in the Cloud
Containers in OpenStack: Leverage OpenStack services to make the most of Docker, Kubernetes and Mesos
Continuous Delivery Handbook: Non Programmer’s Guide to DevOps, Microservices and Kubernetes
The DevOps 2.3 Toolkit: Kubernetes: Deploying and managing highly-available and fault-tolerant applications at scale (The DevOps Toolkit Series)
The DevOps 2.4 Toolkit: Continuous Deployment To Kubernetes: Continuously deploying applications with Jenkins to a
DevOps: Puppet, Docker, and Kubernetes
DevOps with Kubernetes: Accelerating software delivery with container orchestrators
Devops with Kubernetes: Non-Programmer's Handbook
Docker and Kubernetes for Java Developers: Scale, deploy, and monitor multi-container applications
Getting Started with Istio Service Mesh: Manage Microservices in Kubernetes
Getting Started with Kubernetes
Getting Started with Kubernetes - Second Edition: Orchestrate and manage large-scale Docker deployments
Getting Started with Kubernetes: Extend your containerization strategy by orchestrating and managing large-scale container deployments, 3rd Edition
Hands-On Microservices with Kubernetes: Build, deploy, and manage scalable microservices on Kubernetes
Kubernetes: A Step-By-Step Guide For Beginners To Build, Manage, Develop, and Intelligently Deploy Applications By Using Kubernetes (2020 Edition)
Kubernetes Administration I: A Hands-On Guide to Certified Kubernetes Administrator Exam
Kubernetes Best Practices
Kubernetes: Build and Deploy Modern Applications in a Scalable Infrastructure. The Complete Guide to the Most Modern Scalable Software Infrastructure. (Docker & Kubernetes Book 2)
Introduction to DevOps with Kubernetes: Build scalable cloud-native applications using DevOps patterns created with Kubernetes
The Kubernetes Book: Version 3 - Updated 2020
Kubernetes - A Complete DevOps Cookbook: Build and manage your applications, orchestrate containers, and deploy cloud-native services
Kubernetes: The Complete Guide To Master Kubernetes (March 2019 Edition)
Kubernetes Cookbook: Building Cloud Native Applications
Kubernetes Cookbook: Practical solutions to container orchestration, 2nd Edition
Kubernetes cluster (The DevOps Toolkit Series)
Kubernetes Design Patterns and Extensions: Enhance your container-cluster management skills and efficiently develop and deploy applications
Kubernetes for Developers: Use Kubernetes to develop, test, and deploy your applications with the help of containers
Kubernetes for Serverless Applications: Implement FaaS by effectively deploying, managing, monitoring, and orchestrating serverless applications using Kubernetes
Kubernetes Handbook: Non-Programmer’s Guide to Deploy Applications with Kubernetes
Kubernetes in Action
Kubernetes Microservices with Docker
Kubernetes on AWS: Deploy and manage production-ready Kubernetes clusters on AWS
Kubernetes Operators
Kubernetes Patterns
Kubernetes: The Updated Guide to Master Kubernetes for Everyone (January 2020 Version)
Kubernetes: The Ultimate Guide to Learn and Master Kubernetes for Beginners and Advanced Users (2020 Edition)
Kubernetes: Up and Running: Dive into the Future of Infrastructure
Learn Kubernetes - Container orchestration using Docker (Learn Collection)
Mastering Kubernetes: Large scale container deployment and management
Mastering Kubernetes: Master the art of container management by using the power of Kubernetes, 2nd Edition
Managing Kubernetes: Operating Kubernetes Clusters in the Real World
Programming Kubernetes: Developing Cloud-Native Applications
Pro SQL Server on Linux: Including Container-Based Deployment with Docker and Kubernetes
Scalable Container Infrastructures with Docker, Kubernetes and OpenShift - 2019 Edition (English Edition): The Compendium on Container Clusters for Enterprise Administrators and DevOps Teams

How Do You Change The Port That GitLab Listens on?

Problem scenario
By default GitLab runs on port 8080.  You want to run something else on the server with GitLab.  How do you change the port that GitLab uses?

Solution
1.  Edit the /etc/gitlab/gitlab.rb file.

Find the stanzas with for the "external_url".

Change it from this:  http://x.x.x.x/

to this:  http://x.x.x.x:555

(where x.x.x.x is either the external IP address or FQDN of the gitlab server and 555 is the desired non-standard port number that you want GitLab to listen on).

2.  Then run this command:  sudo gitlab-ctl reconfigure

What Can You Do to Set up Jira when It Hangs Forever with No Error Messages?

Problem scenario
You connect your Jira instance to an empty SQL database.  For the first time you log into the web UI to set things up.  When you try to create a task, project or story, the web UI hangs forever.  If you close out of the web UI, you have to start all over.  

What do you do when you first connect to a Jira instance via its web UI and it prompts you for a language and other initial settings but hangs when you try to create a task or story?

Possible Solution #1
Bypass any intermediate device such as a reverse proxy, load balancer or VIP.   Try to connect directly to the Jira instance. 

Possible Solution #2
1.  Log into the web UI as an administrator.  
2.  Go to the gear/sprocket icon in the upper right hand corner and click that icon.
3.  Go to System.
4.  Go to System Info.  
5.  Click on the option to "Force garbage collection."
6.   Now try again.

Possible Solution #3
Configure the OS or Jira to never use swap memory (or virtual memory).  (For the OS change, you could look at this posting to get an idea of how to do this; this posting does focus on adding swap space.  But it could be beneficial to figuring out how to eliminate it from the OS entirely.  You may prefer to try to configure Jira so it never uses virtual memory.)

Possible Solution #4
Try a different web browser.  Chrome may allow Jira to work if you were having a problem with a different web browser.

Possible Solution #5
This possible solution is especially advisable if you are receiving a "Detected URL scheme https does not match the expected scheme http" error in the web UI at the time you log in.  Modify the server.xml file -- but don't just uncomment the multi-line comment sections.  Modify the top "catalina" section of server.xml.  Verify the settings are correct for your environment.  You may want to look at documentation on Atlassian.com to verify your settings are acceptable.

How Do You Know If a Program Ended Because It Completed Successfully, Had an Error, or Another User Interactively Terminated the Running Program?

Problem scenario
You believe that there are three main ways a program runs:  one it completed successfully, two an error made the program stop, or three another user on the server interactively terminated the program when it was still running.  You want to identify which one of these three possibilities happened.  How do you know if the program that just ran stopped because it completed successfully, had an error, or another user manually killed the running program?

Solution
Naturally Linux commands can do different things from what a human expects.  Some of these outcomes are considered "successes" insofar as the Linux OS is concerned.  To find which of the three outcomes happened, run this command: echo $?

The result will normally be a 0, 1 or 2.  To interpret this integer result, read the following:

  • A program that completes because it finished successfully will have an exit code of "0".
  • A program that ended with an error will have an exit code of "1".
  • An interrupted program will have an exit code of "2".  (The interrupt signal will stop a program correspond to the program's exit status being a 2.)

What Is a Dockerfile and What Is a Docker Image?

Question / Problem scenario
You know what a Docker container is.  What is a Dockerfile and what is a Docker image?

Answer to What is a Dockerfile?
"Dockerfiles are used to define how a container should look at build time, but they do not manage the container's ongoing state, and cannot be used to manage the Docker host system." (Page 5 of Docker Up & Running by Matthias & Kane, O'Reilly Press, 2015.)

It is "a manifest that describes how a Docker image is built" according to page 26 of Docker Cookbook by Sebastien Goasguen, published by O'Reilly Press 2016.

"Docker can build images automatically by reading the instructions from a Dockerfile." taken from Docker.com.

Answer to What is a Docker image?

A file that is necessary for launching a Docker container.   "Docker images consist of one or more filesystem layers and some important metadata that represent all the files required to run a Dockerized application."
(Page 26 of Docker Up & Running by Matthias & Kane, O'Reilly Press, 2015.)

Each instruction in a Dockerfile "creates a new Docker image layer." (Page 43 of Docker Up & Running by Matthias & Kane, O'Reilly Press, 2015.)

A Dockerfile is needed to create a Docker image.  A Docker image is needed to create a Docker container.