Showing posts with label yaml. Show all posts
Showing posts with label yaml. Show all posts

Sunday, March 6, 2022

Kubernetes Clusters Part 4: Manifest file



Manifest file is a yaml file or in other words it is a configuration file....lol

Manifest file most basic infrastructure:
  1. apiVersion
  2. kind
  3. metada (name, label)
  4. spec (containers)
Do note that even if you declare only these properties for your pods, kubernetes will still auto create alooot of other properties.

USE VISUAL STUDIO CODE to edit, simpler cause it can auto template for you and also it is a word editor.

pod.yaml manifest file

apiVersion: v1
kind: Pod        #(P should be capital!)
metadata:
  name: pod1    #(all should be small letters)
  labels:
    name: nginx-app
spec:
  containers:
  - name: c1
    image: nginx  
  - name: c2
    image: tomcat



Tuesday, March 1, 2022

Docker Compose

 


Docker Compose
it is a microservice approach to create containers and manage containers for orchestration.
docker-compose is a tool for defining and running multi-container Docker applications. With docker-compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Using Compose is basically a three-step process:
1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
3. Run docker-compose up and Compose starts and runs your entire app.

Docker Compose commands:

docker-compose up -d

This will create a network, and create the containers as per defined in the docker-compose.yml file

docker-compose down

This will stop and remove the containers then it will remove the network. The containers stopped and removed are as of defined in the docker-compose.yml file.

docker-compose scale db=2

If for exam[le in the docker-compose.yml file, you specified a db container, using the scale command, it will create for you 2 db containers.


Install Docker compose file

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

docker-compose --version

Example 1:


version: '3.3' 
services: 
         db: 
                 image: mysql:5.7 
                 volumes: 
                   - db_data:/var/lib/mysql 
                 restart: always 
                 environment: 
                     MYSQL_ROOT_PASSWORD: somewordpress 
                     MYSQL_DATABASE: wordpress 
                     MYSQL_USER: wordpress 
                     MYSQL_PASSWORD: wordpress 

         wordpress: 
             depends_on: 
                     - db 
                         image: wordpress:latest 
                         ports:
                          - "80:80" 
                         restart: always 
                         environment: 
                             WORDPRESS_DB_HOST: db:3306 
                             WORDPRESS_DB_USER: wordpress 
                             WORDPRESS_DB_PASSWORD: wordpress 
                             WORDPRESS_DB_NAME: wordpress 
                        volumes: 
                          db_data: {}


docker-compose up -d
docker-compose down


Example 2
version: '3.3' 
services: 
     db: 
         image: ramansharma95/mysql 
     webapp: 
         image: ramansharma95/webapp 
         ports: 
             - "80:80"

Run the following command in mysql container:

docker exec -it <<containerid>> bash 
mysql -uroot -pwhizlabs
create database company;
use company;
create table employee ( name varchar(30), mobile varchar(30));
select * from employee;

Tuesday, February 22, 2022

EXTRA INFO: YAML origins and overview


YAML firstly introduced as a markup language. thus YAML stands for Yet Another Markup Language. but then it was found out that it actually is a data representation language so they changed the acronym to: YAML Aint'a Markup Language. 

Lol 

  • It is python based Language.
  • It is widely used in DevOps tools like Docker, Kubernetes, and Ansible.
  • You need to indent your code properly otherwise it throws syntax - Error.
  • .yml or .yaml is the extension of YAML files.
  • It stores the data in the following formats:

a) key-value pair:
                -name: ansible
b) collection:
                -names:
                        - Irfan
                        - Rahman
                        - Ayyub


YAML Ain't Markup Language is a data serialization language that matches user’s expectations about data. It designed to be human friendly and works perfectly with other programming languages. It is useful to manage data and includes Unicode printable characters. This chapter will give you an introduction to YAML and gives you an idea about its features

Now that you have an idea about YAML and its features, let us learn its basics with syntax and other operations. Remember that YAML includes a human readable structured format.

Rules for Creating YAML file

When you are creating a file in YAML, you should remember the following basic rules −

  • YAML is case sensitive

  • The files should have .yaml or .yml as the extension

  • YAML allows spaces for indentation.

Basic Components of YAML File

The basic components of YAML are described below −

Conventional Block Format

This block format uses hyphen+space to begin a new item in a specified list. Observe the example shown below −

--- # Favorite movies
 - DDLJ
 - Sholye
 - Sahid

Inline Format

Inline format is delimited with comma and space and the items are enclosed in JSON. Observe the example shown below −

--- # Shopping list
   [mobile,laptop,HDMI Cable,Router]

Folded Text

Folded text converts newlines to spaces and removes the leading whitespace. Observe the example shown below −

- {name: Raman Sharma, age: 40}
- name: Manoj
  age: 27

The structure which follows all the basic conventions of YAML is shown below −

men: [Raman, Manoj]
women:
  - Mary 
  - Susan 


Synopsis of YAML Basic Elements

  • The synopsis of YAML basic elements is given here: Comments in YAML begins with the (#) character.

  • Comments must be separated from other tokens by whitespaces.

  • Indentation of whitespace is used to denote structure.

  • Tabs are not included as indentation for YAML files.

  • List members are denoted by a leading hyphen (-).

  • List members are enclosed in square brackets and separated by commas.

  • Associative arrays are represented using colon ( : ) in the format of key value pair. They are enclosed in curly braces {}.

  • Multiple documents with single streams are separated with 3 hyphens (---).

  • Repeated nodes in each file are initially denoted by an ampersand (&) and by an asterisk (*) mark later.

  • YAML always requires colons and commas used as list separators followed by space with scalar values.

  • Nodes should be labelled with an exclamation mark (!) or double exclamation mark (!!), followed by string which can be expanded into an URI or URL.

Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...