How Do You Run Docker commands without sudo?

Problem scenario
For security reasons, you do not want to have to use "sudo" to elevate your privileges when you run docker commands.  What should you do?

Solution
1.  Run these commands as the user that will be able to run docker commands:
sudo groupadd docker
sudo gpasswd -a $USER docker
newgrp docker

2.  Install Docker.  See this posting if you need directions.

3.  Run these commands:
sudo systemctl enable docker
sudo systemctl start docker

4.  Reboot the server.  

5.  You are done.  Going forward you should be able to run docker commands without sudo.  You can test it by running this: docker run hello-world

How Do You Deploy a Kubernetes Cluster into AWS with a RHEL Server?

Problem scenario
You want to create a Kubernetes cluster in AWS via a RHEL server.  What should you do?

Solution
This will deploy additional resources in your AWS account (not on to the RHEL server). It will cost money to follow these directions.

Prerequisites

i.  Install and configure the AWS CLI (or awscli). If you need help, see this posting.

ii.  Install kubectl.  If you need assistance, follow step #1 only of this posting.

iii.  Install kops (Kubernetes Operations command) by running these commands:

curl -Lk https://github.com/kubernetes/kops/releases/download/1.8.1/kops-linux-amd64 > /tmp/kops-linux-amd64

chmod +x /tmp/kops-linux-amd64

sudo mv /tmp/kops-linux-amd64 /usr/local/bin/kops

iv.  You need to have SSH keys set up.  You want to have a .pub file in your ~/.ssh/ directory. The directions below assume that your .pub file is id_rsa.pub; adjust the directions below when they refer to this file if you have a different name for it.

If you do not know how to create this file, run this command and press enter twice:

ssh-keygen -t rsa -P ""

Procedures
(We created these directions based on a Linoxide.com article.)

1.a.  Create a script called "aws.sh" in /tmp/ with the following lines:

#!/bin/bash
aws iam create-group --group-name kops

aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEC2FullAccess --group-name kops

aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonRoute53FullAccess --group-name kops

aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess --group-name kops

aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/IAMFullAccess --group-name kops

aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonVPCFullAccess --group-name kops

aws iam create-user --user-name kops

aws iam add-user-to-group --user-name kops --group-name kops

aws iam create-access-key --user-name kops
#This comment is the last line. EOF.

1.b.  Run this: source /tmp/aws.sh
The "source" command is necessary if all your AWS CLI commands on the system will work in the current shell (which is often the case if you followed the AWS configure directions available elsewhere on this website).

2.  Run these five commands (the fifth is a multi-line command) interactively (but replace us-west-9 with the region of your choice, e.g., us-east-1; to see the options available, click here):

export KOPS_CLUSTER_NAME=contint.k8s.local
rn=us-west-9


aws s3api create-bucket --bucket ${KOPS_CLUSTER_NAME}-state --region $rn --create-bucket-configuration LocationConstraint=$rn

export KOPS_STATE_STORE=s3://$KOPS_CLUSTER_NAME-state

# This command will place in the "a" zone of the region (i.e., us-west-9) the cluster:

kops create cluster \
 --name=${KOPS_CLUSTER_NAME} \
 --zones=$rn"a" \
 --master-size="t2.micro" \
 --node-size="t2.medium" \
 --node-count="3" \
 --ssh-public-key="~/.ssh/id_rsa.pub"

3.  You are done. To confirm the cluster was created, run this command:  kops get cluster

Here are possible commands (but substitute "contint" with the name you entered before ".k8s.local" in first command in step #2):

 * list clusters with: kops get cluster
 * edit this cluster with: kops edit cluster contint2.k8s.local
 * edit your node instance group: kops edit ig --name=contint2.k8s.local nodes
 * edit your master instance group: kops edit ig --name=contint2.k8s.local master-us-west-2a

What Is The Difference between AWS CodeDeploy and AWS CodeCommit?

Question
AWS has PaaS services called CodeDeploy and CodeCommit.  What are the differences between these?

Answer
"AWS CodeDeploy is a fully managed deployment service that automates software deployments to a variety of compute services such as Amazon EC2, AWS Fargate, AWS Lambda, and your on-premises servers."  (Taken from https://aws.amazon.com/codedeploy/.)

"AWS CodeCommit is a fully-managed source control service that hosts secure Git-based repositiories."  (Taken from https://aws.amazon.com/codecommit/.)

AWS CodeCommit is a repository of code.  CodeDeploy may use a repository of code in its automation of deploying software to various AWS components and [EC-2] servers.

What Is The Difference between AWS CodeBuild and AWS CodeCommit?

Question
AWS has PaaS services called CodeBuild and CodeCommit.  What are the differences between these?

Answer
"AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy."  (Taken from https://aws.amazon.com/codebuild/.)

"AWS CodeCommit is a fully-managed source control service that hosts secure Git-based repositiories."  (Taken from https://aws.amazon.com/codecommit/.)

AWS CodeCommit is a PaaS repository of code.  CodeBuild is a service that prepares code to be deployed; CodeBuild is a CI process that may involve a code repository such as AWS CodeCommit.

What Is The Difference between AWS CodeBuild and AWS CodeDeploy?

Question
AWS has PaaS services called CodeBuild and CodeDeploy.  What are the differences between these?

Answer
"AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy."  (Taken from https://aws.amazon.com/codebuild/.)

"AWS CodeDeploy is a fully managed deployment service that automates software deployments to a variety of compute services such as Amazon EC2, AWS Fargate, AWS Lambda, and your on-premises servers."  (Taken from https://aws.amazon.com/codedeploy/.)

CI is the automated convergence of code from two or more developers.  CodeBuild facilitates the CI process.  AWS CodeDeploy specializes in a component of the CI process: deploying to AWS components and [EC-2] servers.

What Is The Difference between AWS CodeDeploy and AWS CodePipeline?

Question
AWS has PaaS services called CodeDeploy and CodePipeline.  What are the differences between these?

Answer
"AWS CodeDeploy is a fully managed deployment service that automates software deployments to a variety of compute services such as Amazon EC2, AWS Fargate, AWS Lambda, and your on-premises servers."  (Taken from https://aws.amazon.com/codedeploy/.)

"AWS CodePipeline is a fully managed continuous delivery service that helps you automate your release pipelines for fast and reliable application and infrastructure updates."  (Taken from https://aws.amazon.com/codepipeline/.)

AWS CodeDeploy is primarily for deploying code that is ready to be deployed to various AWS components and [EC-2] servers.  AWS CodePipeline is a tool for automating the deployment (and integration) of code from two or more developers to a variety of different servers (including on-premise hardware).

What Is The Difference between AWS CodeBuild and AWS CodeDeploy?

Question
AWS has PaaS services called CodeBuild and CodeDeploy.  What are the differences between these?

Answer
"AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy."  (Taken from https://aws.amazon.com/codebuild/.)

"AWS CodeDeploy is a fully managed deployment service that automates software deployments to a variety of compute services such as Amazon EC2, AWS Fargate, AWS Lambda, and your on-premises servers." (Taken from https://aws.amazon.com/codedeploy/.)

AWS CodeBuild is primarily for preparing software for deployment.  AWS CodeDeploy is primarily for doing the deployment of code that is ready to be deployed.

What Is The Difference between AWS CodeBuild and AWS CodePipeline?

Question
AWS has PaaS services called CodeBuild and CodePipeline.  What are the differences between these?

Answer
"AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy." (This was taken from https://aws.amazon.com/codebuild/.)

"AWS CodePipeline is a fully managed continuous delivery service that helps you automate your release pipelines for fast and reliable application and infrastructure updates."  (This was taken from https://aws.amazon.com/codepipeline/.)

CI is the automated convergence of code from two or more developers.  Continuous delivery is the use of a CI pipeline wherein the final promotion of the code to production is done through manual means.  Continuous delivery is the application of CI.  Therefore AWS CodeBuild does not do all that the AWS CodePipeline does.

What Is The Difference between AWS CodeCommit and AWS CodePipeline?

Question
AWS has PaaS services called CodeCommit and CodePipeline.  What are the differences between these?

Answer
"AWS CodeCommit is a fully-managed source control service that hosts secure Git-based repositiories."  (Taken from https://aws.amazon.com/codecommit/.)

"AWS CodePipeline is a fully managed [sic] continuous delivery service that helps you automate your release pipelines for fast and reliable application and infrastructure updates."  (Taken from https://aws.amazon.com/codepipeline/.)

AWS CodeCommit is a PaaS repository of code.  AWS CodePipeline is a specific type of CI pipeline that may use a code repository such as CodeCommit.

How Do You Get an Ansible Command to Issue a Long-Running Bash Command and Keep Processing?

Problem scenario
You have a playbook that runs a shell command.  But this command never completes.  If you cancel the playbook, you find the processes started from the playbook cancel from the cancellation of the playbook too.  You want the process to keep running while Ansible moves to the next command.  You want processes to run in a detached way that is independent of the playbook execution itself.  You want the playbook to have a finite duration while allowing the Linux command to continue processing. What do you do to get the Ansible playbook to complete while leaving long-running (including processes that run indefinitely) Linux processes/commands running that were started by the playbook itself?

Solution
Root cause

The Ansible playbook generally waits for the Linux command to return a success or failure.  It does not keep processing until the Linux command is completed.

Possible solution #1
Prepend this string to the Bash command itself: "nohup "
Append this string, without the quotes, to the end of the Bash command: "> /dev/null 2>&1 &"

Possible solution #2
If the Linux command starts a service that runs indefinitely, create a foobar.service file where "foobar" is the name of the service.  Place this file in /etc/systemd/system/.   Now you can re-write your Ansible playbook to use the built in "service" module rather than the raw Linux commands.  To learn about how to create a .service file, look at solution #2 of this article.

Possible solution #3
Use the "async" and "poll" attributes.  Alternatively you can use the pause module after a long-running command such as the one above.  This link has more information.  The word "pause" is reserved and can take attributes "minutes" or "seconds".  Pausing for 10 seconds after the shell (or raw Linux) command can allow for the Ansible playbook to continue running while allowing the command to run on its own.