How Do You Troubleshoot the kubectl ‘version “extensions/v1beta1″‘ Error Message?

Problem scenario
You run a kubectl command, but you get this problem: 'error: unable to recognize "foobar.yaml": no matches for kind "Deployment" in version "extensions/v1beta1"'

What should you do?

Solution
Change your yaml file so the apiVersion setting/value works. To learn more about the acceptable values, see this posting.

How Do You Replace a Pattern with a String in Bash?

Problem scenario
You have a .txt file. You know Linux can support substitutions of strings with some type of expression. You want to use Bash to replace every occurrence in the file with a string. What should you do?

Solution
Let's assume the file you have is called coolfile.txt. Run these two commands to replace "foo" with "bar" every time "foo" is found in the file named coolfile.txt:

oldfile=$(cat coolfile.txt)
echo "${oldfile//'foo'/bar}" > newfile.txt
# The resulting file newfile.txt will have "bar" instead of "foo"

How Do You Escape or Break from a Method in Python?

Problem scenario
You want to quit a function, or return out of it, when a certain condition is met. How do you do this?

Solution
This program illustrates how it is done. You will want to run the program twice, once by leaving the "5" as it is, and a second time by changing the "5" to "6".

def cool(x):
  if x == 5:
    return "There was equivalence"
  else:
    y = x
  print("This statement is printing as an illustration")
  return "The comparison was NOT equivalent"

var1 = cool(5)
print(var1)

How Do You Troubleshoot a C Program That Prints a Warning Message like “expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=]”?

Problem scenario
You compile a C program (with gcc foobar.cc) but you get an error message like this:

basicprog.c:5:13: warning: format '%d' expects argument of type 'int', but argument 2 has type 'char *' [-Wformat=]
printf ("y is a %d\n",y);

What do you do to not get this error?

Solution
While the code compiles, the executable may not run.  A compilation error can be benign.  For this case, string characters need a special syntax to be printed out.  

Here is a line that will produce this error (with a variable named "y"):

   printf ("y is a %d\n", y);

Here is a similar but corrected line that will be error free:

  printf ("y is a %s\n",y);

The "%d" is appropriate for printing integer variables.  For string variables, use "%s" syntax.


For learning about the C programming language, you may want to purchase a book below:

0131103628C Programming Language, 2nd Edition by Pearson
1718501048Effective C: An Introduction to Professional C Programming by No Starch Press
1789349915Learn C Programming: A beginner's guide to learning C programming the easy and disciplined way by Packt Publishing
1789343623Extreme C: Taking you to the limit in Concurrency, OOP, and the most advanced capabilities of C by Packt Publishing
0393979504C Programming: A Modern Approach, 2nd Edition by W. W. Norton & Compan

How Do You Use Terraform and Kubernetes in a Simple Way (as a Proof of Concept)?

Problem scenario
You want to use Terraform and Kubernetes (in EKS). How do you do this in a simple way to test it out?

Solution
Prerequisite

This assumes you have deployed EKS. If you need assistance, see this posting.
This assumes you have installed Terraform. If you need assistance, see this posting.

Procedures

  1. This first step is optional. Log into the AWS Management Console, and go here. Take a screenshot.
  2. Go to the back-end server with Terraform. Run these commands:
git clone https://github.com/hashicorp/learn-terraform-provision-eks-cluster
cd learn-terraform-provision-eks-cluster/
terraform init
terraform plan  # This command is optional
terraform apply

# It may take 20 minutes.  This step "module.eks.aws_eks_cluster.this[0]: Still creating... " may take 15 minutes by itself.  Be patient.
  1. This step is optional. Go back to the web UI and refresh the web page to view the new VPC changes.
  2. Go back to the command prompt and run this command to rollback the changes: terraform destroy

How Do You Fix the AWS CLI Error “Following required service principals [eks.amazonaws.com] were not found in the trust relationships”?

Problem scenario
You run an AWS CLI command, but you get this error:

An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: Following required service principals [eks.amazonaws.com] were not found in the trust relationships of clusterRole arn:aws:iam::12345678910:role/foobar

How do you fix this?

Solution
Draft a command like this (but replace "12345677810:role/foobar" with the equivalent string in the error, and replace foobar.amazonaws.com with the service principal in the error):

aws iam list-roles --query 'Roles[?Arn==arn:aws:iam::12345678910:role/foobar]' | grep foobar.amazonaws.com

If the above command returns nothing, try the command again without the "| grep foobar.amazonaws.com". If your Role was configured correctly, you may need to open a ticket with AWS Support. If nothing is returned from the command above with the "grep", you need to modify the role. Go to the AWS Management Console, go to IAM -> Roles. Click on the role, go to "Trust Relationships" and "Edit Trust Relationship." Modify it like this:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "foo.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    },
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "bar.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

A List of PowerShell Books

1593279183PowerShell for Sysadmins: Workflow Automation Made Easy by No Starch Press
1617294160Learn Windows PowerShell in a Month of Lunches by Manning Publications
1449320686Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell by O'Reilly Media
1789536669Mastering Windows PowerShell Scripting: Automate and manage your environment using PowerShell Core 6.0, 3rd Edition by Packt Publishing
B085RQNL9XWindows PowerShell and Scripting for Beginners: Complete Beginners Guide to learn Windows PowerShell and its Scripting by Independently published
1617295094Learn PowerShell Scripting in a Month of Lunches by Manning Publications
0735675112Windows PowerShell Step by Step by Microsoft Press
1789808537Windows Server 2019 Automation with PowerShell Cookbook: Powerful ways to automate and manage Windows administrative tasks, 3rd Edition by Packt Publishing
1449320961Windows PowerShell Pocket Reference: Portable Help for PowerShell Scripters (Pocket Reference (O'Reilly)) by O'Reilly Media
1119560713Windows Server 2019 & PowerShell All-in-One For Dummies (For Dummies (Computer/Tech)) by For Dummies
1633430294Windows PowerShell in Action by Manning Publications
B085XGXCD5Powershell: The Ultimate Guide to Learning and Understanding Powershell Programming
B085KBSVTFPowerShell for Beginners: The Complete Guide to Master Windows PowerShell Scripting by Independently published
B0731CVMTHPowerShell for Office 365: Automate Office 365 administrative tasks by Packt Publishing
1761032704Powershell: The ultimate beginner's guide to Powershell, making you a master at Windows Powershell command line fast! by Ingram Publishing
B08GGBZP13PowerShell: The Ultimate Beginners Guide to Learn PowerShell Step-by-Step by Publishing Factory
B07YSWM2VDPowerShell: The Complete Beginners Guide for Windows PowerShell.: A Step by Step Guide for PowerShell Scripting! by SJ Publishing
1484263871Building Better PowerShell Code: Applying Proven Practices One Tip at a Time by Apress
1484245032PowerShell and Python Together: Targeting Digital Investigations by Apress

How Do You Test the “mount -a” Command to Verify Sufficient Permissions on a Linux VM?

Problem scenario
You want to test "mount -a" to verify your user has sufficient permissions. You cannot add a physical device to the Linux server. How do you confirm "mount" will work?

Solution
Create a directory to be a mount point:
sudo mkdir /aaa
Find a block device to mount. One way would be to run this: sudo cat /proc/partitions
Once found, run this: sudo mount /dev/dm-2 /aaa

Run this command: sudo mount -l | grep aaa
Then the ouput will be something like this: /dev/mapper/foobar on /aaa type ext4 (rw, …)
Copy the /dev/mapper/foobar /aaa ext4 entries (all three). Back up the /etc/fstab file to /etc/fstab.bak
Update the /etc/fstab to have the three entries recently identified as the last line. For example, the last line will look something like this:
/dev/mapper/foobar /aaa ext4

Unmount the newly mapped partition by using a command like this: sudo umount /dev/dem-2
Now run sudo mount -a
Run this command: sudo mount -l | grep aaa