Thursday, September 24, 2020

How to Create a Basic Docker Container

 How to create a basic Docker container


Step 1: install docker in your pc, laptop or vm.

# sudo apt-get install docker.io

# sudo systemctl start docker

# sudo systemctl enable docker

Step 2: create a directory for testing purposes and access such folder

# mkdir Dockerfiles

# cd Dockerfiles

Step 3: Create a docker file and call it Dockerfile

# vi Dockerfile

# Specify the base image to use, gets downloaded automatically

FROM ubuntu

# Specify the maintainer and email address

MAINTAINER *** <***@gmail.com

RUN apt-get update

# Specify the command to run

CMD [#echo", "Hello guys...! from my first image"]

Step 4: Build your image and tag it

# sudo docker build -t myimage:1.0 .

    Sending build context to Docker daemon  2.048kB

    Step 1/4 : FROM ubuntu

     ---> bb0eaf4eee00

    Step 2/4 : MAINTAINER *** <***@gmail.com>

     ---> Using cache

     ---> 2c30cf6f43fb

    Step 3/4 : RUN apt-get update

     ---> Using cache

     ---> 832660e5cdc3

    Step 4/4 : CMD ["echo", "Hello guys...! from my first image"]

     ---> Using cache

     ---> 168e1047d6a4

    Successfully built 168e1047d6a4

    Successfully tagged myimage:1.0

Step 5: List the images available

$ sudo docker image list

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

myimage             1.0                 b6f0f1350590        2 minutes ago       95.8MB

ubuntu              latest              bb0eaf4eee00        8 days ago          72.9MB

Step 6: Run the image for testing purposes

# sudo docker run image_id

    Hello guys...! from my first image

Final Note: 

You can pull more images to play with using sudo docker pull image_name

How to Deploy a Kubernetes Pod in vSphere

 What is a Kubernetes Pod?

A Pod is a Kubernetes structure that is used as a wrapper for one or multiple containers. Kubernetes manages pods rather than the containers directly.

1. Use kubectl to login and access your namespace. Create a yaml file like the one shown here. 


2. Use the kubectl apply command and point to the yaml file. 


3. Verify that the pod was created in the namespace.


4. Use the kubectl describe deployment command to learn about the pod created.



5. Modify the yaml file to scale the pod from one to three. Run the apply command.


6. Verify that there are three pods now.



How to build a Namespace with vSphere for Kubernetes

 What is a Namespace in Kubernetes?

Namespaces are a feature that is use to divide cluster resources between multiple users. 

How to create a Namespace:

1. Launch the vSphere Client and log in as the administrator. Click on Create Namespace.



2. Select your vSphere Cluster and name it. Click on Create.


3. Verify that the Namespace has been created and click on Got It.


4. Click on Add Permissions


5. Specify the user, the identity source and the permissions for the user. 


6. Click on Add Storage and specify the storage policy. 


7. Use the kubectl commadn to test your user. 




How to Install and Use Docker

 Step 1: Install Docker in a linux vm or physical machine. Ubuntu will be used in this demo.

# sudo apt-get install docker.io


Step 2: Start and enable docker

# sudo systemctl start docker

# sudo systemctl enable docker


Step 3: Verify the version of docker

# sudo docker -v

Docker version 19.03.8, build afacb8b7f0


Step 4: Learn about subcommands on your own

# sudo docker

Usage:      docker [OPTIONS] COMMAND

 A self-sufficient runtime for containers

 Options:

      --config string      Location of client config files (default

                           "/home/javier/.docker")

  -c, --context string     Name of the context to use to connect to the

                           daemon (overrides DOCKER_HOST env var and

                           default context set with "docker context use")

  -D, --debug              Enable debug mode

  -H, --host list          Daemon socket(s) to connect to

  -l, --log-level string   Set the logging level

                           ("debug"|"info"|"warn"|"error"|"fatal")

                           (default "info")

      --tls                Use TLS; implied by --tlsverify

      --tlscacert string   Trust certs signed only by this CA (default

                           "/home/javier/.docker/ca.pem")

      --tlscert string     Path to TLS certificate file (default

                           "/home/javier/.docker/cert.pem")

      --tlskey string      Path to TLS key file (default

                           "/home/javier/.docker/key.pem")

      --tlsverify          Use TLS and verify the remote

  -v, --version            Print version information and quit

 Management Commands:

  builder     Manage builds

  config      Manage Docker configs

  container   Manage containers

  context     Manage contexts

  engine      Manage the docker engine

  image       Manage images

  network     Manage networks

  node        Manage Swarm nodes

  plugin      Manage plugins

  secret      Manage Docker secrets

  service     Manage services

  stack       Manage Docker stacks

  swarm       Manage Swarm

  system      Manage Docker

  trust       Manage trust on Docker images

  volume      Manage volumes

 Commands:

  attach      Attach local standard input, output, and error streams to a running container

  build       Build an image from a Dockerfile

  commit      Create a new image from a container's changes

  cp          Copy files/folders between a container and the local filesystem

  create      Create a new container

  deploy      Deploy a new stack or update an existing stack

  diff        Inspect changes to files or directories on a container's filesystem

  events      Get real time events from the server

  exec        Run a command in a running container


Step 5: Test docker by running "hello world"

# sudo docker run hello-world

Hello from Docker!

This message shows that your installation appears to be working correctly.

 To generate this message, Docker took the following steps:

 1. The Docker client contacted the Docker daemon.

 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

    (amd64)

 3. The Docker daemon created a new container from that image which runs the

    executable that produces the output you are currently reading.

 4. The Docker daemon streamed that output to the Docker client, which sent it

    to your terminal.

 To try something more ambitious, you can run an Ubuntu container with:

 For more examples and ideas, visit:

 https://docs.docker.com/get-started/

Step 6: Download an image

# sudo docker pull postgres


Step 7: Verify the number of images that were pulled

# sudo docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

postgres            latest              0f10374e5170        2 weeks ago         314MB

hello-world         latest              bf756fb1ae65        4 months ago        13.3kB


Step 8: Start an access a container

# sudo docker run postgres

# sudo docker ps -a

# sudo docker run -it postgres bash


Other Commands to know:

# sudo docker stop container_id (graceful shutdown)

# sudo docker kill container_id (non graceful shutdown)

# sudo docker rm container_id (delete a stopped container)

# sudo docker build . (build your own container)





Monday, September 21, 2020

How to Deploy and Enable Kubernetes in vSphere 7

 Requirements:

    A three node HA and DRS cluster

    A vCenter Server

    NSX already configured

    The proper license


Step 1: Using the vSphere Client, click on Menu and select Workload Menu. Click on Enable.


Step 2: Select your three node cluster and click on Next.




Step 3: Select the size of the Control Plane and click on Next.



Step 4: Specify your network settings. These appliances will have two IPs each.



Step 5: Configure your CIDRs and API Server endpoint.



Step 6: Provide the Storage related settings for the nodes and disks.


Step 7: Review your settings/values and click on Finish. 


Step 8: After clicking on Finish, walk away and wait until the procedure ends.


Step 9: Once done, you will see  a pool and three appliances created and running. 


Step 10 Next, download the kubectl utility into a windows or linux machine by using for example tools like wget. There is a .zip file that contains the software to view and control Namespaces available using the control plane node ip address (the load balancer created automatically via NSX). Just point your browser to that IP using https.