Tuesday, March 8, 2022

Kubernetes Service Assignment

1. Create a deployment for a webapp (ramansharma95/webapp) on port 80 (replica =1)

2. Create a deployment for a dbapp (ramansharma95/mysql) on port 3306 (replica=1)

3. Create a NodePort service(name of service webservice) for webapp and nodeport value is 31000.

4. Create a ClusterIP service(name of service db) for dbapp.

5. The webservice should communicate to db. (In webapp there is a connection string which points to db) 


4 comments:

Naveen said...

1. vi deploy-webapp.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
labels:
app: webapp
spec:
replicas: 1
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp-container
image: ramansharma95/webapp
ports:
- containerPort: 80
2. vi deploy-mysql.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql-container
image: ramansharma95/mysql
ports:
- containerPort: 3306
3. vi np-webapp.yaml
apiVersion: v1
kind: Service
metadata:
name: webservice
labels:
app: webapp
spec:
selector:
app: webapp
type: NodePort
ports:
- nodePort: 31000
port: 80
targetPort: 80
4. vi np-mysql.yaml
apiVersion: v1
kind: Service
metadata:
name: db
labels:
app: mysql
spec:
selector:
app: mysql
type: ClusterIP
ports:
- port: 3306
targetPort: 3306
5. http://NODE-IP:NODEPORT on browser
able to access employee registration form
unable to add record, recall docker networking tutorial
access db container
kubectl exec -it <> bash
access mysql
mysql -uroot -pwhizlabs
create database company;
show databases;
database is reflected
use company;
create table employee (name varchar(30), mobile varchar(30));
try adding records on webapp
Record added successfully
check records in db
select * from employee;
records are reflected.
Done

ken said...

ken
kubectl run dbapp --image=ramansharma95/mysql:latest --port=3306
kubectl run webapp --image=ramansharma95/webapp:latest --port=80

Jerome said...

1. Create a deployment for a webapp (ramansharma95/webapp) on port 80 (replica =1)
-> vi webapp.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deploy
labels:
app: webapp-app
spec:
replicas: 1
template:
metadata:
labels:
app: webapp-app
spec:
containers:
- name: webapp-container
image: ramansharma95/webapp
ports:
- containerPort: 80
selector:
matchLabels:
app: webapp-app

-> kubectl create -f webapp.yml
-> kubectl get po -o wide (Running)

2. Create a deployment for a dbapp (ramansharma95/mysql) on port 3306 (replica=1)
-> cp webapp.yml dbapp.yml
-> vi dbapp.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: dbapp-deploy
labels:
app: dbapp-app
spec:
replicas: 1
template:
metadata:
labels:
app: dbapp-app
spec:
containers:
- name: dbapp-container
image: ramansharma95/mysql
ports:
- containerPort: 3306
selector:
matchLabels:
app: dbapp-app

-> kubectl create -f dbapp.yml
-> kubectl get po -o wide (Running)

3. Create a NodePort service(name of service webservice) for webapp and nodeport value is 31000.
-> vi webservice.yml
apiVersion: v1
kind: Service
metadata:
name: webservice
labels:
app: web-app
spec:
selector:
app: web-app
type: NodePort
ports:
- nodePort: 31000
port: 31000
targetPort: 80

-> kubectl create -f webservice.yml
-> kubectl get svc (running)

4. Create a ClusterIP service(name of service db) for dbapp.
-> vi dbservice.yml
apiVersion: v1
kind: Service
metadata:
name: dbservice
labels:
app: db-app
spec:
selector:
app: db-app
type: ClusterIP
ports:
- protocol: TCP
port: 3306
targetPort: 80

-> kubectl create -f dbservice.yml
-> kubectl get svc (running)

5. The webservice should communicate to db. (In webapp there is a connection string which points to db) 
-> kubectl describe svc webservice

Asyraf said...

1. Create a deployment for a webapp (ramansharma95/webapp) on port 80 (replica =1)

vi webapp.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
labels:
app: web-app
spec:
replicas: 1
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: webapp
image: ramansharma95/webapp
ports:
- containerPort: 80
selector:
matchLabels:
app: web-app



2. Create a deployment for a dbapp (ramansharma95/mysql) on port 3306 (replica=1)

vi dbapp.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: dbapp
labels:
app: mysql
spec:
replicas: 1
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: dbapp
image: ramansharma95/mysql
ports:
- containerPort: 3306
selector:
matchLabels:
app: mysql


3. Create a NodePort service(name of service webservice) for webapp and nodeport value is 31000.

vi webservice.yaml

apiVersion: v1
kind: Service
metadata:
name: webservice
labels:
app: nginx-app
spec:
selector:
app: nginx-app
type: NodePort
ports:
- nodePort: 31000
port: 80
targetPort: 80

kubectl create -f webservice.yaml
kubectl get svc

4. Create a ClusterIP service(name of service db) for dbapp.

vi db.yaml

apiVersion: v1
kind: Service
metadata:
name: db
labels:
app: mysql
spec:
selector:
app: mysql
type: ClusterIP
ports:
- port: 3306
targetPort: 3306


kubectl create -f db.yaml
kubectl get svc

5. The webservice should communicate to db. (In webapp there is a connection string which points to db)

localhost:31000 (can connect to webserver)

kubectl exec -it dbapp-6cbcc8bffb-xf2rw bash

mysql -uroot -pwhizlabs

Create a database company

show databases;

create database company;

show databases;

use company;

create table employee ( name varchar(30), mobile varchar(30));

select * from employee

Post a Comment