Skip to content

Commit

Permalink
docs: Add new commands
Browse files Browse the repository at this point in the history
Update README.md

Update README.md

docs: Added YAML config for k8s

Update README.md

Update README.md

docs: updated new commands
  • Loading branch information
Pradumnasaraf committed Nov 18, 2022
1 parent 57ae0f0 commit 4e64830
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 99 deletions.
138 changes: 44 additions & 94 deletions Docker/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ docker pull <image name>
- `-p <Hot port:container port>`- To fowrad the port.
- `-d` - To run in detached mode
- `-it` - For interactive envirnoment
- `-e` - For environment variable

```bash
docker run <image name>
//Eg: docker run nginx
```

- We can aslo pass a complete `.env` file

```bash
--env-file <path-to-env-file>
Eg: --env-file ./.env
```

### Docker Container

- To stop a running conatiner
Expand Down Expand Up @@ -84,7 +92,7 @@ docker exec -it <container ID/name> bash/sh
- To check which ports has been exposed and forwarded

```bash
docker port <container name>
docker port <image name>
```

- Check all the stopped container
Expand Down Expand Up @@ -117,12 +125,21 @@ docker container prune -f
docker network ls
```

- Inspect a network components
- Inspect a network components, like which container are attached to that network.

```bash
docker network inspect <network name>
```

- Run a container on a certian network/own careted network

```
docker run --network <network-name> <image-name>
```

```
docker inspect --format "{{.NetworkSettings.IPAddress}}" <conatiner-name>
```

### Docker Images

Expand All @@ -144,6 +161,19 @@ docker rmi $(docker images -q)
docker inspect <image name/id>
```

- Check the image layers formation

```bash
docker history <image-name>
```

- Create a our own image with an existing image.

```
docker image tag <image-name with tag> <new-image name with tag>
docker image tag nginx pradumna/nginx:hello
```

### Docker Volume

- Create bind mount
Expand All @@ -163,19 +193,10 @@ docker run -v <path-on-folder-loacl-machine>:<path-to-folder-on-container> -v <p
```
To make it read only so that when you add some files inside it the container and it will not get created on you local machine use `-v port:port:ro`

### Docker Compose

- To override the and ENV of a docker container, here PORT
```
-e PORT=3500
```
or file

```bash
--env-file <path-to-env-file>
Eg: --env-file ./.env
```

TO run docker compose file
- Run docker compose file.
Note: By default it finds for the file name `docker-compose.yaml`, to give file with other naming use `-f <file-name.yaml>` command

```bash
docker compose up -d
Expand All @@ -184,93 +205,22 @@ docker compose up -d
```bash
docker compose down
```
- When we run docker compose while with the existing image it will not create build the image even tho there is some changes. It runs the stale version.

```
docker compose up --build
```

To override the existing config:

```bash
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml
```

- To list all the networks

```bash
docker network ls
```

To inspect a particular network
- To rebuilt the new Image with thew new changes

```bash
docker inspect <network-id>
docker compose up --build
```

to check which port are exposed in a container
- Override the existing of compose file

```bash
docker container port <Container-name>
````

```
docker inspect --format "{{.NetworkSettings.IPAddress}}" <conatiner-name>
```
- To inspect which conatiners are attached to the a particalr newtork
```
docker network inspect <network-name>
docker network inspect bridge
```
- To create a network (It will create a bridge)
```
docker network create <network-name>
```
- To run a container on a certian network/own careted network
```
docker run --network <network-name> <image-name>
```
- To connect a conatanier to a another network
```
docker connect network <network-name> <conatiner-name>
```
- To disconnect a conatanier from another network
```
docker disconnect network <network-name> <conatiner-name>
```
- Check the image layers formation
```bash
docker history <image-name>
```

- Inspect the meta data of an image

```
docker inspect <image-name>
```

- To create a our own tag with some image

```
docker image tag <image-name with tag> <new-image name with tag>
docker image tag nginx pradumna/nginx:hello
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml
```

> DOCKER SWARM and SERVICE
### Docker Swam and Services

- To initalize swarm
- Initalize swarm

```bash
docker swarm init
Expand All @@ -294,13 +244,13 @@ docker node update --role manager <node-name>
docker network create -d overlay backend
```

- To craete a service
- Create a service. Also we can add flags for further customiztaion.

- `--name` - to give a service name
- `--replicas` - to define how many running instance of the same image.
- `-p` - for port forwarding

```
```bash
docker service create -p 8080:80 --name vote --replicas 2 nginx
```

Expand Down Expand Up @@ -335,7 +285,7 @@ docker service update --publish-rm 8080 --publish-add 808180 <service name>
docker service update --publish-rm 8080 --publish-add 808180 mynginx
```

> DOCKER STACK
### Docker Stack

- To deploy a stack file

Expand Down
52 changes: 49 additions & 3 deletions Kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@ Follow requests when some things need to change/added to a worker node

#### Namespaces

- Isolated environment for the teams. In this, we can group resources separately like a database. Also, great for running different versions of the app.
- Isolated environment, we can group resources separately like a database. Also, great for running different versions of the app.

We can add namespace attribute in YAMl file to specify with one it belongs to


```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mongodb-configmap
namespace: my-namespace
data:
database_url: mongodb-service
```
We can create a namespace by
Expand Down Expand Up @@ -119,7 +132,9 @@ spec:
### Services
Services are for internal communication of pods. It also helps give a pop static IP address
Services are for internal communication of pods. It also helps give a pop static IP address. Contains routing rules.
```yaml
apiVersion: v1
Expand All @@ -137,7 +152,36 @@ spec:
### Ingress
It is use for an external service, which can be accessed by an URL instaed of IP-PORT
It is use for an external trafic/request, which can be accessed by an URL instaed of `IP-PORT - 17.28.55.44.5:7800`. For that we need an ingress controller to make work of ingress.

![Ingress](https://user-images.githubusercontent.com/51878265/201585224-eca055af-eeb6-473c-bd96-33af9b5f6c55.png)

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kubernetes-ingress
namespace: kubernetes-dashboard
spec:
rules:
- host: example.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: kubernetes-dashboard
port:
number: 80
```

TLS

<img width="1512" alt="Screenshot 2022-11-14 at 1 17 55 PM" src="https://user-images.githubusercontent.com/51878265/201604299-264768c3-e5b1-48fa-9bc1-3762a3052006.png">



### ConfigMap

Expand Down Expand Up @@ -180,3 +224,5 @@ All the Cluster info is stored in the file name `config` with the path:
```bash
~/.kube/config
```


36 changes: 36 additions & 0 deletions Kubernetes/YAML/Ingress/multiple-path.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kubernetes-ingress
namespace: kubernetes-dashboard
spec:
rules:
- host: example.com # This is the domain name that you want to use for your website
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: kubernetes-dashboard # This is the name of the service
port:
number: 80 # This is the port of the service
# Have different paths for different services
- pathType: Prefix
path: "/app"
backend:
service:
name: app-service
port:
number: 3000
# Multiple most by creating subdomains
- host: blog.example.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: blog-service
port:
number: 8080
22 changes: 22 additions & 0 deletions Kubernetes/YAML/Ingress/tls-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myingress
labels:
name: myingress
spec:
tls:
- hosts:
- example.com
secretName: mysecret # This is the name of the secret that you created
rules:
- host: example.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: <Service>
port:
number: 8080
6 changes: 6 additions & 0 deletions Kubernetes/YAML/Mongo/mongo-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mongodb-configmap
data:
database_url: mongodb-service
32 changes: 32 additions & 0 deletions Kubernetes/YAML/Mongo/mongo-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo-deployment
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongodb-secrets
key: mongo-root-username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secrets
key: mongo-root-password
Loading

0 comments on commit 4e64830

Please sign in to comment.