Monday, July 18, 2022

Docker Compose

  • Docker Compose is used for running multiple containers as a single service. 
  • Each of the containers here run in isolation but can interact with each other when required.
  • Kubernetes and Docker Compose are both container orchestration frameworks. 
  • Kubernetes runs containers over a number of computers, virtual or real.  
  • Docker Compose runs containers on a single host machine.
     

     
 File : docker-compose.yml
version: '3'
services:
webapp1:
image: nginx
ports:
- "8000:80"
webapp2:
image: nginx
ports:
- "8002:80"
 
 

NOTE:Default file name is docker-compose,you can define your docker-compose file using below syntax

docker-compose -f docker-compose2.yml up -d
(-d for background ) 
Commands:

docker-compose create ( depreciated ,create only container and does not create network)
docker-compose up --no-start ( create only container with default network)
docker-compose rm ( to remove container )
docker-compose start ( To start container )
docker-compose stop ( To stop container )

docker-compose rm ( To delete container )
docker-compose images ( To view images )
docker container ls
docker-compose ps ( To check state of container )
docker-compose pause ( To pause any container )
docker-compose unpause ( To unpause any container ) 
 

docker-compose up -d  
docker-compose down

 

docker-compose kill ( To kill containers )
docker-compose start
docker-compose port webapp1 80 ( To check public accessible port )
docker-compose logs -f ( To check online logs )

docker-compose ps
docker containers ls -a

docker-compose exec webapp1 ls ( To run ls command inside running container )
docker-compose run webapp1 ls ( To run ls command inside a new  container and container went down )


docker-compose restart ( To restart container )
docker-compose pull ( Pull image from registry )
docker-compose push ( push  image to the  registry )
docker-compose --version

 File :docker-compose.yml
version: '3'
services:
webapp1:
image: nginx
webapp2:
image: nginx
 
docker-compose scale webapp1=4 webapp2=4 ( To scale )
docker-compose top ( To view running process )
 
 
 To be continue....



	
	
	
	


 

 

Friday, July 15, 2022

Kubernetes Namespaces

Namespaces are a way to organize clusters into virtual sub-clusters — they can be helpful when different teams or projects share a Kubernetes cluster. 


 


Namespaces allow to split-up resources into different groups. Resource names should be unique in a namespace. We can use namespaces to create multiple environments like dev, staging and production etc.

Kubernetes comes with three namespaces out-of-the-box. They are:

 1. default: this is the namespace that is referenced by default   for every    Kubernetes command, and where every Kubernetes resource is located by default.
 Until new namespaces are created, the entire cluster resides in ‘default’.
 2.  kube-system: Used for Kubernetes components
 3.  kube-public: Used for public resources.



To create namespace

> kubectl create ns development
> kubectl create ns production

To view namespaces

> kubectl get namespaces
> kubectl get ns

Define namespace in a yaml file:
metadata:
   name  : pod4
   namespace: development


To view namespace along with associated pods

> kubectl get pods --all-namespaces

To change default namespace

>kubectl config set-context --current --namespace=development

To delete a namespace

> kubectl delete namespace development

NOTE:Everything in the namespace including all services, running pods, and artifacts will be deleted