How I pass the CKA exam

How to prepare

  1. The environment to test the exam is ubuntu, so you need to have knowledge about unix/linux
  2. Have knowledge about the Docker. Here is the free course about basic Docker that provide you an overview of Docker: https://techiescamp.com/courses/learn-container-basics-docker-podman/
  3. Kodecloud course
  4. Killer shell
    • When you schedule the exam, you have free 1 time to access the kill shell to do the mock test. Overview, the layout of environment is similar with the actual such as time fame, question area, virtual environments.
    • You have 36hours to access the killer shell, try to maximum access the killer. Tips: starting a session, try to resolve it in the time fame. when you have few remain minutes, clicking the button to end the timer and reveal the answers. you will get the score. From the incomplete question, it show the solution. read the solution and try it in current session. And then, click on the reset lab to try another session to practice. Try to prevent the lab session from reach to ending. if it ends, you can not reset a new lab to practice again.
    • The solution is opened in the other web page, you can save it to your laptop after 36hrs accessible time fame.
  5. Another resource: https://devopscube.com/kubernetes-tutorials-beginners/ https://devopscube.com/kubernetes-architecture-explained/

During the exam

  • Time management: Having from 15-20 questions to resolve in 120 minute. The easy and difficult questions is arranged randomly. Don’t stuck in any questions. Maybe, the next one will be easy. The best way to do is: First, attempt the question, try to resolve it in few minutes, it you can, flag it to note that you will back to do it again. Move to the next question, it maybe the easier question, you can resolve it in few minute. Continue to do this. After you reach the end of question, turn back to resolve those marked questions.
  • Exam space: it can be your room. Yes, I tested in my room, but you must Clean all stuff in the desk you will sit to do the exam. The proctors will ask you to show around your room, area under the desk, drawers, and ask to remove items that are not allowed. They allow ask you to put your phone reach out of your hand but can reach to call for support if have any technical issues. But there are chatting box to chat with proctors if having any issue. no need to use your phone
  • Environment test: using alias k for kubectl; have existed command to use: jq; tmux; curl; man
  • Kubernetes Documentation: https://kubernetes.io/docs/ and their subdomains; https://kubernetes.io/blog/ and their subdomains. But in every question, alway show the hyperlink of related contents.
  • ExamUI: This is an example: https://docs.linuxfoundation.org/tc-docs/certification/tips-cka-and-ckad#adjusting-font-and-windows-in-the-examui

Some important tips

In the actual test, you would get those questions:

Read the K8S cheatsheet, some question is resolve by using the cheatsheet https://kubernetes.io/docs/reference/kubectl/cheatsheet/

Some question have the solution is an example of K8S document. How to know it, do the mock test above, and I recognized that. And again, it happened in the actual test.

CREATE SEPARATE /var/lib ON EBS VOLUME AWS

Firstly, I just want to thank for the post: http://bhargavamin.com/how-to-do/create-separate-var-partition-ebs-volume-aws/

if your disk needs to partition, and has a label, context file, the post as above is exactly for you.

But, my post is all you need if you don’t need to  partition your disk, and no label in your partition :

$ ls -Zd /var/lib/

? /var/lib/

Let’s do now:

Step 1: Create the volume in AWS Console and attach it to the instance

Step 2 : Format the below partition using

$ sudo mkfs -t ext4 /dev/xvdd

Noted: please write down/ copy the UUID of this disk. or you can get from /dev/disk/by-uuid

$ ls -la /dev/disk/by-uuid

Step 3: Mount the formatted partition on /mnt

$ sudo mount /dev/xvdd /mnt

Step 4 : Copy over data from /var/lib to /mnt

$ sudo rsync -aulvXpogtr /var/lib/* /mnt

Step 5 : Umount from /mnt

$ sudo umount /mnt

Step 6 : Make the entry in fstab as below:

UUID=<uuid-of-the-disk-get-from-step-2> /var/lib ext4 defaults 1 2

Step 7: Change the /var/lib to a new location and create another /var/lib directory and mount the new volume:

$ sudo mv /var/lib /var/lib.old
$ sudo mkdir /var/lib

Step 8 : This time use the mount -a in verbose mode as below:

$ sudo mount -av

Noted: you doesn’t to reboot your server. But it your server doesn’t show as you expect, just reboot your server.

 

 

 

Restoring MySQL database from physical files (Debian/Ubuntu)

On a Monday morning, going to my office normally but I got that my server was shutdown due to broken power.  When I reboot the server, it could not boot as normal because of missing Grub. Taking two days to recover it but it  was no lucky. I decided to install a fresh server and restore Mysql database from physical files after mounting the hard disk of old server to new one.

If you fall in that case, your hard disk is work but server cannot boot up, you can follow this post as a reference.

ref:  http://stackoverflow.com/a/484773/1920536  but you don’t need to shutdown your server.

Step 1. Shutdown Mysql server

Step 2. Copy database in your database folder (in linux, the default location is /var/lib/mysql). Keep same name of the database, and same name of database in mysql mode.

 sudo cp -rf   /mnt/ubuntu_426/var/lib/mysql/database1 /var/lib/mysql/

Step 3:  Change own and change mode the folder:

sudo chown -R mysql:mysql /var/lib/mysql/database1
sudo chmod -R 660 /var/lib/mysql/database1 
sudo chmod 700 /var/lib/mysql/database1

Step 4: Copy ibdata1 in your database folder

sudo cp /mnt/ubuntu_426/var/lib/mysql/ibdata1 /var/lib/mysql/

sudo chown mysql:mysql /var/lib/mysql/ibdata1

Step 5: copy  ib_logfile0 and  ib_logfile1 files in your database folder.

sudo cp /mnt/ubuntu_426/var/lib/mysql/ib_logfile0 /var/lib/mysql/

sudo cp /mnt/ubuntu_426/var/lib/mysql/ib_logfile1 /var/lib/mysql/

Remember change own and change root of those files:

sudo chown -R mysql:mysql /var/log/mysql/ib_logfile0

sudo chown -R mysql:mysql /var/log/mysql/ib_logfile1

or

sudo chown -R mysql:mysql /var/log/mysql

Step 6 (Optional): My site has configuration to store files in a specific location, then I copy those to corresponding location, exactly.

Step 7: Start your Mysql server. Everything come back and enjoy it.

That is.

Note: if you doesn’t do step 4, you can get an error:

InnoDB: The log sequence in ibdata files is higher
InnoDB: than the log sequence number in the ib_logfiles! Are database?
InnoDB: you are using the right ib_logfiles to start up the database?
InnoDB: Log sequence number in ib_logfiles in 6316712, log
InnoDB: sequence numbers stamped to ibdata file headers are between
InnoDB: 24916633497 and 24916633497

to resolved it, you can do as step 4 above

or remove your log files: mv /var/lib/mysql/ib_logfile* /tmp/. Then Start MySQL server. This will create new logs;

ref: http://dba.stackexchange.com/a/120673

 

 

 

 

 

 

 

 

 

Automatically accept all SDK licences

When branding app in Jenkins server which only install SDK, sometimes SDK licenses cannot be updated automatically and you get the error:

Error:

11:59:46.697 [ERROR] [org.gradle.BuildExceptionReporter] 
11:59:46.710 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
11:59:46.710 [ERROR] [org.gradle.BuildExceptionReporter] 
11:59:46.710 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
11:59:46.716 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred configuring project ':data'.
11:59:46.716 [ERROR] [org.gradle.BuildExceptionReporter] > You have not accepted the license agreements of the following SDK components:
11:59:46.717 [ERROR] [org.gradle.BuildExceptionReporter]   [Android SDK Platform 24].
11:59:46.718 [ERROR] [org.gradle.BuildExceptionReporter]   Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
11:59:46.718 [ERROR] [org.gradle.BuildExceptionReporter]   Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

Soluction:

 echo y | android update sdk --no-ui --all --filter "extra-android-m2repository

 

Change username running Jenkins

When we install Jenkins on server (Mac or Linux), Jenkins always  create jenkins as owner Jenkins folder under /Users/Shared/. Then, if we run a command, we can get like that:

ls -la /Users/Shared/Jenkins/Home

total 112

drwxr-xr-x   27 jenkins  jenkins   918 Oct 18 16:37 .

drwxr-xr-x    8 jenkins  jenkins   272 Oct 18 16:09 ..

-rw-r–r–    1 jenkins  jenkins    54 Oct 18 15:53 .owner

-rw-r–r–    1 jenkins  jenkins   365 Oct 18 14:37 com.dabsquared.gitlabjenkins.GitLabPushTrigger.xml

-rw-r–r–    1 jenkins  jenkins   604 Oct 18 16:37 com.dabsquared.gitlabjenkins.connection.GitLabConnectionConfig.xml

-rw-r–r–    1 jenkins  jenkins  3726 Oct 18 10:31 config.xml

-rw-r–r–    1 jenkins  jenkins   159 Oct 18 16:37 hudson.model.UpdateCenter.xml

-rw-r–r–    1 jenkins  jenkins   370 Oct 18 10:27 hudson.plugins.git.GitTool.xml

-rw——-    1 jenkins  jenkins  1712 Oct 18 10:23 identity.key.enc

-rw-r–r–    1 jenkins  jenkins     4 Oct 18 16:37 jenkins.install.InstallUtil.lastExecVersion

-rw-r–r–    1 jenkins  jenkins     4 Oct 18 10:30 jenkins.install.UpgradeWizard.state

-rw-r–r–    1 jenkins  jenkins   138 Oct 18 10:31 jenkins.model.DownloadSettings.xml

-rw-r–r–    1 jenkins  jenkins   169 Oct 18 10:31 jenkins.security.QueueItemAuthenticatorConfiguration.xml

drwxr-xr-x    3 jenkins  jenkins   102 Oct 18 14:51 jobs

drwxr-xr-x    3 jenkins  jenkins   102 Oct 18 10:23 logs

-rw-r–r–    1 jenkins  jenkins   907 Oct 18 16:37 nodeMonitors.xml

drwxr-xr-x    2 jenkins  jenkins    68 Oct 18 10:23 nodes

drwxr-xr-x  146 jenkins  jenkins  4964 Oct 18 16:37 plugins

-rw-r–r–    1 jenkins  jenkins   129 Oct 18 16:36 queue.xml.bak

-rw-r–r–    1 jenkins  jenkins    64 Oct 18 10:23 secret.key

-rw-r–r–    1 jenkins  jenkins     0 Oct 18 10:23 secret.key.not-so-secret

drwx——   11 jenkins  jenkins   374 Oct 18 16:09 secrets

drwxr-xr-x    7 jenkins  jenkins   238 Oct 18 10:27 updates

drwxr-xr-x    3 jenkins  jenkins   102 Oct 18 10:23 userContent

drwxr-xr-x    3 jenkins  jenkins   102 Oct 18 10:30 users

drwxr-xr-x   25 jenkins  jenkins   850 Oct 18 10:23 war

drwxr-xr-x    2 jenkins  jenkins    68 Oct 18 10:28 workflow-libs

There isn’t a problem if we install Jenkins under user jenkins. However, if we install Jenkins in our account( for me it is /Users/linhnguyen), Jenkins doesn’t enough permission to access a number of our files or folder and vice versa.

To prevent it, we can change default owner of jenkins to our account. To do that,

  1. Edit Username in /Library/LaunchDaemons/org.jenkins-ci.plist
    sudo emacs /Library/LaunchDaemons/org.jenkins-ci.plist
    
    UserName
    
        jenkins
    
        linhnguyen
  2. Change owner of the directory:
    sudo chown -R linhnguyen /Users/Shared/Jenkins/
  3. Change oner of Jenkins log:
    sudo chown -R linhnguyen /var/log/jenkins
  4. Restart Jenkins
  5. sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
  6. sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

dyld: lazy symbol binding failed

Sometimes, when you run a command in a terminal, you got an error like that:

dyld: lazy symbol binding failed: Symbol not found: _rb_str_new_static

  Referenced from: /Users//.gems/gems/json-2.0.2/lib/json/ext/generator.bundle

  Expected in: flat namespace

dyld: Symbol not found: _rb_str_new_static

  Referenced from: /Users//.gems/gems/json-2.0.2/lib/json/ext/generator.bundle

  Expected in: flat namespace

I already google and read many threads in Stackoverflow  but it is no lucky. Then, I found that:

This is because your environment is configured to install gems in the home directory location of ~/.gem, probably by setting GEM_HOME and GEM_PATH to that location or by having similar ~/.gemrc or /etc/gemrc settings.

rbenv doesn’t work well with the user install location since it’s hard for it to pick up executables from there. Besides that, I had GEM_HOME defined and using an older version of Ruby through rbenvmade bundler cease working, thatGEM_HOME causes problems. unset GEM_HOME and viola, gem install bundle installed to the correct ~/.rbenv/shims location and then bundle worked.

 emacs ~/.bash_profile

#export GEM_HOME="$HOME/.gems"                                                                                                                             

if which rbenv > /dev/null;

  then eval "$(rbenv init -)";

fi

 

RESIZING EL CAPITAN MAC VOLUMES UNDER VMWARE (ESXi, Worktation ..)

Apple has made some changes to Disk Utility in OS X 10.11 El Capitan. One of the biggest changes is how the partition tab looks and functions.

To resize the disk in VMWare:

First,  Increase the size of the virtual disk in VMWare.

Second, make VM recognize the disk.

In 10.11 we are presented with this

Screen Shot 2016-03-31 at 11.38.47 AM

So we can see that the VMWare Virtual Disk is 214,75 GB, but our Macintosh HD volume is only 3107,16 GB

And Disk Utility can’t seem to see the extra space!

Fortunately its a trivial task to achieve the same goal using the command line.
So bust open Terminal.app and enter the following command (This will resize the Volume at / (Macintosh HD) to the maximum (R))

sudo diskutil resizeVolume / R
Resizing to full size (fit to fill)
Started partitioning on disk0s2 SSD01
Verifying the disk
Verifying file system
Using live mode
Performing live verification
Checking Journaled HFS Plus volume
Checking extents overflow file
Checking multi-linked files
Checking catalog hierarchy
Checking extended attributes file
Checking volume bitmap
Checking volume information
The volume SSD01 appears to be OK
File system check exit code is 0
Resizing
Waiting for the disks to reappear
Finished partitioning on disk0s2 SSD01
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *214.7 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS SSD01                   213.9 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s4

Noted:It you run the command, It returns the error:
Error: -5341: MediaKit reports partition (map) too small; if you recently grew your whole-disk, you should run whole-disk repair

To fixed it, run

sudo diskutil repairDisk /dev/disk0

then run again the command

sudo diskutil resizeVolume / R

If you want to information of the disk, run:

sudo diskutil info /dev/disk0

Upgrade Apache from 2.2.22 to 2.4 on Debian 7 64bit?

Apache 2.2.22 is the stable distribution for Debian 7

You will need to compile Apache from source code. Debian doesn’t automatically update its software in stable (or wheezy); there’s a reason why it’s the stable distribution but it is possible.

Another way:

sudo emacs /etc/apt/sources.list
        deb http://ftp.de.debian.org/debian sid main 
sudo apt-get update 
sudo apt-get -t sid install apache2

Ubuntu and Debian: Adding .conf Extensions

Follow these instructions at any time to update your virtual host configuration files. This change will work with Apache 2.2, so you can make it ahead of time. You can also do it right after you upgrade to Apache 2.4 to make your sites work again.

  1. Use the mv command to rename each virtual host file in your /etc/apache2/sites-available/directory to include the .conf extension:
  2. Make simple link in sites-enable/ directory to include the .conf extension with sites-available/

    All Distros: Permissions

    If you are utilizing access control rules within your virtual host files, you will need to follow these instructions to update your permissions for Apache 2.4. You cannot add the Require all granted line in Apache 2.2, or you’ll get a 500 Internal Server Error. Make this change just after updating to Apache 2.4.

Within the VirtualHost block for this website, locate or create the Directory block for your website’s public directory. Add the line Require all granted. (If the line Require all denied is already there, update it to Require all granted)

<Directory /path/to/public/website/>
   Require all granted
</Directory>

How can I convert a DMG to ISO on Mac OS X

Disk Utility can  convert a dmg to iso on MAC OS.

Use Convert then select your dmg file.

In the Save As dialog that follows, select DVD/CD master.

Disk Utility will insist on saving the new ISO as a .cdr file, but it is really an ISO.

A way to convert a .cdr to an .iso is:

$ hdiutil makehybrid -iso -joliet -o [filename].iso [filename].cdr

GPG error “NO_PUBKEY”?

when we get an error like that:

W: GPG error: http://ppa.launchpad.net trusty Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6C

We can fix as below:

sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 4F4EA0AAE5267A6C

then

sudo apt-get update

If the error happens in Debian, it should be resolved as below:

apt-get install debian-keyring
gpg --keyserver pgp.mit.edu --recv-keys 4F4EA0AAE5267A6C
gpg --armor --export 4F4EA0AA | apt-key add -

sudo apt-get update