Skip to content

Commit e97154e

Browse files
Kalyan Reddy DaidaKalyan Reddy Daida
authored andcommitted
Welcome to Stack Simplify
1 parent ad73d87 commit e97154e

File tree

10 files changed

+801
-0
lines changed

10 files changed

+801
-0
lines changed

02-Docker-Fundamentals/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Docker Fundamentals
2+
- For Docker Fundamentals github repository, please click on below link
3+
- https://github.com/stacksimplify/docker-fundamentals
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Kubernetes - PODs
2+
3+
## Step-01: PODs Introduction
4+
- What is a POD ?
5+
- What is a Multi-Container POD?
6+
7+
## Step-02: PODs Demo
8+
### Get Worker Nodes Status
9+
- Verify if kubernetes worker nodes are ready.
10+
```
11+
# Get Worker Node Status
12+
kubectl get nodes
13+
14+
# Get Worker Node Status with wide option
15+
kubectl get nodes -o wide
16+
```
17+
18+
### Create a Pod
19+
- Create a Pod
20+
```
21+
# Template
22+
kubectl run <desired-pod-name> --image <Container-Image>
23+
24+
# Replace Pod Name, Container Image
25+
kubectl run my-first-pod --image stacksimplify/kubenginx:1.0.0
26+
```
27+
28+
### List Pods
29+
- Get the list of pods
30+
```
31+
# List Pods
32+
kubectl get pods
33+
34+
# Alias name for pods is po
35+
kubectl get po
36+
```
37+
38+
### List Pods with wide option
39+
- List pods with wide option which also provide Node information on which Pod is running
40+
```
41+
kubectl get pods -o wide
42+
```
43+
44+
### What happened in the backgroup when above command is run?
45+
1. Kubernetes created a pod
46+
2. Pulled the docker image from docker hub
47+
3. Created the container in the pod
48+
4. Started the container present in the pod
49+
50+
51+
### Describe Pod
52+
- Describe the POD, primarily required during troubleshooting.
53+
- Events shown will be of a great help during troubleshooting.
54+
```
55+
# To get list of pod names
56+
kubectl get pods
57+
58+
# Describe the Pod
59+
kubectl describe pod <Pod-Name>
60+
kubectl describe pod my-first-pod
61+
```
62+
63+
### Access Application
64+
- Currently we can access this application only inside worker nodes.
65+
- To access it externally, we need to create a **NodePort or Load Balancer Service**.
66+
- **Services** is one very very important concept in Kubernetes.
67+
68+
### Delete Pod
69+
```
70+
# To get list of pod names
71+
kubectl get pods
72+
73+
# Delete Pod
74+
kubectl delete pod <Pod-Name>
75+
kubectl delete pod my-first-pod
76+
```
77+
78+
## Step-03: Load Balancer Service Introduction
79+
- What are Services in k8s?
80+
- What is a Load Balancer Service?
81+
- How it works?
82+
83+
## Step-04: Demo - Expose Pod with a Service
84+
- Expose pod with a service (Load Balancer Service) to access the application externally (from internet)
85+
- **Ports**
86+
- **port:** Port on which node port service listens in Kubernetes cluster internally
87+
- **targetPort:** We define container port here on which our application is running.
88+
```
89+
# Create a Pod
90+
kubectl run <desired-pod-name> --image <Container-Image>
91+
kubectl run my-first-pod --image stacksimplify/kubenginx:1.0.0
92+
93+
# Expose Pod as a Service
94+
kubectl expose pod <Pod-Name> --type=LoadBalancer --port=80 --name=<Service-Name>
95+
kubectl expose pod my-first-pod --type=LoadBalancer --port=80 --name=my-first-service
96+
97+
# Get Service Info
98+
kubectl get service
99+
kubectl get svc
100+
101+
# Access Application
102+
http://<External-IP-from-get-service-output>
103+
```
104+
105+
- **Important Note about: target-port**
106+
- If target-port is not defined, by default and for convenience, the **targetPort** is set to the same value as the **port** field.
107+
108+
## Step-05: Interact with a Pod
109+
110+
### Verify Pod Logs
111+
```
112+
# Get Pod Name
113+
kubectl get po
114+
115+
# Dump Pod logs
116+
kubectl logs <pod-name>
117+
kubectl logs my-first-pod
118+
119+
# Stream pod logs with -f option and access application to see logs
120+
kubectl logs <pod-name>
121+
kubectl logs -f my-first-pod
122+
```
123+
- **Important Notes**
124+
- Refer below link and search for **Interacting with running Pods** for additional log options
125+
- Troubleshooting skills are very important. So please go through all logging options available and master them.
126+
- **Reference:** https://kubernetes.io/docs/reference/kubectl/cheatsheet/
127+
128+
### Connect to Container in a POD
129+
- **Connect to a Container in POD and execute commands**
130+
```
131+
# Connect to Nginx Container in a POD
132+
kubectl exec -it <pod-name> -- /bin/bash
133+
kubectl exec -it my-first-pod -- /bin/bash
134+
135+
# Execute some commands in Nginx container
136+
ls
137+
cd /usr/share/nginx/html
138+
cat index.html
139+
exit
140+
```
141+
142+
- **Running individual commands in a Container**
143+
```
144+
kubectl exec -it <pod-name> env
145+
146+
# Sample Commands
147+
kubectl exec -it my-first-pod env
148+
kubectl exec -it my-first-pod ls
149+
kubectl exec -it my-first-pod cat /usr/share/nginx/html/index.html
150+
```
151+
## Step-06: Get YAML Output of Pod & Service
152+
### Get YAML Output
153+
```
154+
# Get pod definition YAML output
155+
kubectl get pod my-first-pod -o yaml
156+
157+
# Get service definition YAML output
158+
kubectl get service my-first-service -o yaml
159+
```
160+
161+
## Step-07: Clean-Up
162+
```
163+
# Get all Objects in default namespace
164+
kubectl get all
165+
166+
# Delete Services
167+
kubectl delete svc my-first-service
168+
kubectl delete svc my-first-service2
169+
kubectl delete svc my-first-service3
170+
171+
# Delete Pod
172+
kubectl delete pod my-first-pod
173+
174+
# Get all Objects in default namespace
175+
kubectl get all
176+
```
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Kubernetes - ReplicaSets
2+
3+
## Step-01: Introduction to ReplicaSets
4+
- What are ReplicaSets?
5+
- What is the advantage of using ReplicaSets?
6+
7+
## Step-02: Create ReplicaSet
8+
9+
### Create ReplicaSet
10+
- Create ReplicaSet
11+
```
12+
kubectl create -f replicaset-demo.yml
13+
```
14+
- **replicaset-demo.yml**
15+
```yml
16+
apiVersion: apps/v1
17+
kind: ReplicaSet
18+
metadata:
19+
name: my-helloworld-rs
20+
labels:
21+
app: my-helloworld
22+
spec:
23+
replicas: 3
24+
selector:
25+
matchLabels:
26+
app: my-helloworld
27+
template:
28+
metadata:
29+
labels:
30+
app: my-helloworld
31+
spec:
32+
containers:
33+
- name: my-helloworld-app
34+
image: stacksimplify/kube-helloworld:1.0.0
35+
```
36+
37+
### List ReplicaSets
38+
- Get list of ReplicaSets
39+
```
40+
kubectl get replicaset
41+
kubectl get rs
42+
```
43+
44+
### Describe ReplicaSet
45+
- Describe the newly created ReplicaSet
46+
```
47+
kubectl describe rs/<replicaset-name>
48+
49+
kubectl describe rs/my-helloworld-rs
50+
[or]
51+
kubectl describe rs my-helloworld-rs
52+
```
53+
54+
### List of Pods
55+
- Get list of Pods
56+
```
57+
#Get list of Pods
58+
kubectl get pods
59+
kubectl describe pod <pod-name>
60+
61+
# Get list of Pods with Pod IP and Node in which it is running
62+
kubectl get pods -o wide
63+
```
64+
65+
### Verify the Owner of the Pod
66+
- Verify the owner reference of the pod.
67+
- Verify under **"name"** tag under **"ownerReferences"**. We will find the replicaset name to which this pod belongs to.
68+
```
69+
kubectl get pods <pod-name> -o yaml
70+
kubectl get pods my-helloworld-rs-c8rrj -o yaml
71+
```
72+
73+
## Step-03: Expose ReplicaSet as a Service
74+
- Expose ReplicaSet with a service (Load Balancer Service) to access the application externally (from internet)
75+
```
76+
# Expose ReplicaSet as a Service
77+
kubectl expose rs <ReplicaSet-Name> --type=LoadBalancer --port=80 --target-port=8080 --name=<Service-Name-To-Be-Created>
78+
kubectl expose rs my-helloworld-rs --type=LoadBalancer --port=80 --target-port=8080 --name=my-helloworld-rs-service
79+
80+
# Get Service Info
81+
kubectl get service
82+
kubectl get svc
83+
84+
```
85+
- **Access the Application using External or Public IP**
86+
```
87+
http://<External-IP-from-get-service-output>/hello
88+
```
89+
90+
## Step-04: Test Replicaset Reliability or High Availability
91+
- Test how the high availability or reliability concept is achieved automatically in Kubernetes
92+
- Whenever a POD is accidentally terminated due to some application issue, ReplicaSet should auto-create that Pod to maintain desired number of Replicas configured to achive High Availability.
93+
```
94+
# To get Pod Name
95+
kubectl get pods
96+
97+
# Delete the Pod
98+
kubectl delete pod <Pod-Name>
99+
100+
# Verify the new pod got created automatically
101+
kubectl get pods (Verify Age and name of new pod)
102+
```
103+
104+
## Step-05: Test ReplicaSet Scalability feature
105+
- Test how scalability is going to seamless & quick
106+
- Update the **replicas** field in **replicaset-demo.yml** from 3 to 6.
107+
```
108+
# Before change
109+
spec:
110+
replicas: 3
111+
112+
# After change
113+
spec:
114+
replicas: 6
115+
```
116+
- Update the ReplicaSet
117+
```
118+
# Apply latest changes to ReplicaSet
119+
kubectl replace -f replicaset-demo.yml
120+
121+
# Verify if new pods got created
122+
kubectl get pods -o wide
123+
```
124+
125+
## Step-06: Delete ReplicaSet & Service
126+
### Delete ReplicaSet
127+
```
128+
# Delete ReplicaSet
129+
kubectl delete rs <ReplicaSet-Name>
130+
131+
# Sample Commands
132+
kubectl delete rs/my-helloworld-rs
133+
[or]
134+
kubectl delete rs my-helloworld-rs
135+
136+
# Verify if ReplicaSet got deleted
137+
kubectl get rs
138+
```
139+
140+
### Delete Service created for ReplicaSet
141+
```
142+
# Delete Service
143+
kubectl delete svc <service-name>
144+
145+
# Sample Commands
146+
kubectl delete svc my-helloworld-rs-service
147+
[or]
148+
kubectl delete svc/my-helloworld-rs-service
149+
150+
# Verify if Service got deleted
151+
kubectl get svc
152+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apps/v1
2+
kind: ReplicaSet
3+
metadata:
4+
name: my-helloworld-rs
5+
labels:
6+
app: my-helloworld
7+
spec:
8+
replicas: 6
9+
selector:
10+
matchLabels:
11+
app: my-helloworld
12+
template:
13+
metadata:
14+
labels:
15+
app: my-helloworld
16+
spec:
17+
containers:
18+
- name: my-helloworld-app
19+
image: stacksimplify/kube-helloworld:1.0.0

0 commit comments

Comments
 (0)