Kubernetes
Kubernetes
22
Create Deployment based on httpd image
Create service to access step 1 deployment pod
application using load balancers
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep2
labels :
abc : sheshi
spec:
replicas : 3
selector:
matchLabels:
abc: sheshi
template:
metadata:
labels:
abc : sheshi
spec:
containers:
- name: c1
image: httpd
apiVersion: v1
kind: Service
metadata :
name : svc2
spec:
ports:
- port: 80
targetPort: 80
selector:
abc : sheshi
type: LoadBalancer
Create Deployment based on nginx image, tomcat image
Create service to access step 1 deployment pod
application using load Nodeport
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep3
labels :
app : myapp
spec:
replicas : 2
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: nginx
- name: c2
image: tomcat
apiVersion: v1
kind: Service
metadata :
name : svc3
labels :
app : myapp
spec:
ports:
- port: 90
name: prt1
targetPort: 80
- port: 91
name: prt2
targetPort: 8080
selector:
app : myapp
type: NodePort
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep4
labels :
app : newapp
spec:
replicas : 2
selector:
matchLabels:
app : newapp
template:
metadata:
labels:
app : newapp
spec:
nodeSelector:
size: large
containers:
- name: c1
image: nginx
12.09.22
Create Deployment based on nginx image, number
replicas =10
Create a NodePort service to access deployment
application
Test application is accessible or not
Update deployment spec to change image to
apache2
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep1
labels :
app : myapp
spec:
replicas : 5
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: nginx
------
apiVersion: v1
kind: Service
metadata :
name : svc1
labels :
app : myapp
spec:
ports:
- port: 90
targetPort: 80
nodePort: 30010
selector:
app : myapp
type: NodePort
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep1
labels :
app : myapp
spec:
replicas : 5
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: nginx
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep1
labels :
app : myapp
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 1
replicas : 5
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: httpd
livenessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 60
periodSeconds : 30
successThreshold: 1
failureThreshold: 3
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep1
labels :
app : myapp
spec:
replicas : 2
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: nginx
env :
- name: DB_IP
value: ’10.0.0.23’
- name: DB_NAME
value: sheshi
13.09.22
Create a deployment using nginx image,
Note: Deployment strategy “Recreate”
Number of replicas =10
Update a deployment image to httpd
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep1
labels :
app : myapp
spec:
strategy:
type: Recreate
replicas : 5
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: nginx
readinessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 5
periodSeconds : 10
successThreshold: 1
failureThreshold: 2
CONFIGMAP
apiVersion: v1
kind: ConfigMap
metadata:
name: cm1
data:
DB_IP : '10.0.0.56'
DB_name: sheshi
DB_user: varshan
xyz: testing
VOLUME
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep1
labels :
app : myapp
spec:
replicas : 2
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: nginx
volumeMounts:
- mountPath: /tmp
name: v1
volumes:
- name: v1
configMap:
name: cm1
ConfigMap under volume with pipe
AWS:
Duration= 3Month
Fee=40K
Faculty = sheshivardhan
Loc=Hyderabad
Oracle:
Duration= 2Month
Fee=30K
Faculty = sheshivardhan
Loc=Mumbai
Max no.of students=30
apiVersion: v1
kind: ConfigMap
metadata:
name: cm2
data:
DB_IP : '192.168.0.56'
AWS: |
Duration= 3Month
Fee=40K
Faculty = sheshivardhan
Loc=Hyderabad
Oracle: |
Duration= 2Month
Fee=30K
Faculty = sheshivardhan
Loc=Mumbai
Max no.of students=30
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep1
labels :
app : myapp
spec:
replicas : 2
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: nginx
volumeMounts:
- mountPath: /tmp
name: v1
volumes:
- name: v1
configMap:
name: cm2
Daemonset
apiVersion: apps/v1
kind: DaemonSet
metadata :
name : ds
labels :
app : logapp
spec:
selector:
matchLabels:
app : logapp
template:
metadata:
labels:
app : logapp
spec:
containers:
- name: c1
image: nginx
JOB
apiVersion: batch/v1
kind: Job
metadata :
name : jb1
labels :
app : schapp
spec:
selector:
matchLabels:
app : schapp
template:
metadata:
labels:
app : schapp
spec:
containers:
- name: c1
image: nginx
14.09.22
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep1
labels :
app : myapp
spec:
replicas : 2
selector:
matchLabels:
app : myapp
template:
metadata:
labels:
app : myapp
spec:
containers:
- name: c1
image: nginx
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep2
labels :
app : app2
spec:
replicas : 2
selector:
matchLabels:
app : app2
template:
metadata:
labels:
app : app2
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: app2
topologyKey: kubernetes.io/hostname
containers:
- name: c1
image: nginx
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep2
labels :
app : app2
spec:
replicas : 2
selector:
matchLabels:
app : app2
template:
metadata:
labels:
app : app2
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app: app2
topologyKey: kubernetes.io/hostname
weight: 50
containers:
- name: c1
image: nginx
POD Affinity:
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep2
labels :
app : app2
spec:
replicas : 2
selector:
matchLabels:
app : app2
template:
metadata:
labels:
app : app2
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: app2
topologyKey: kubernetes.io/hostname
containers:
- name: c1
image: nginx
TAINT:
apiVersion: apps/v1
kind: Deployment
metadata :
name : dep2
labels :
app : app2
spec:
replicas : 2
selector:
matchLabels:
app : app2
template:
metadata:
labels:
app : app2
spec:
nodeName: ip-192-168-7-100.ap-southeast-
1.compute.internal
containers:
- name: c1
image: nginx