TKG 1.4 on Azure – Part 4 : Deploy the application on workload cluster

Reading Time: < 1 min

Lets deploy a simple web application on workload cluster in Azure that is deployed in our previous post:

#Create new namespace called bba-news
reddye@reddye-a02 tkg % kubectl create ns bba-news
namespace/bba-news created

#List all namespaces

reddye@reddye-a02 tkg % kubectl get ns
NAME STATUS AGE
bba-news Active 78s
default Active 21m
kube-node-lease Active 21m
kube-public Active 21m
kube-system Active 21m
tanzu-package-repo-global Active 20m
tkg-system Active 20m
tkg-system-public Active 20m
  • Though we can create a deployment in declarative way, lets do it using yaml file:
# Create a yaml file with below content. ex: bbanews_deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: bbanews-deploy
namespace: bba-news
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: bbanews
replicas: 3 # tells deployment to run 1 pods matching the template
template: # create pods using pod definition in this template
metadata:
labels:
app: bbanews
spec:
containers:
- name: bbanews-con
image: eknath009/nginx-bbanews
ports:
- containerPort: 80
  • Expose the service using a yaml file. You can also do it using kubectl expose command:
# Create a yaml file for services with below content. For ex: bbanews_service.yaml

apiVersion: v1
kind: Service
metadata:
name: bbanews-svc
namespace: bba-news
labels:
app: bbanews
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: bbanews
type: LoadBalancer
#Execute below commands to create deployment and services: 

reddye@reddye-a02 scripts % kubectl apply -f bbanews_deploy.yaml
deployment.apps/bbanews-deploy created
reddye@reddye-a02 scripts % kubectl apply -f bbanews_service.yaml
service/bbanews-svc created

#List the services in bba-news namespace and note the load balancer IP

reddye@reddye-a02 scripts % kubectl get svc -n bba-news
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
bbanews-svc LoadBalancer 100.68.216.230 20.204.226.62 80:32489/TCP 6m24s

#Check the status of deployment

reddye@reddye-a02 scripts % kubectl get deploy -n bba-news
NAME READY UP-TO-DATE AVAILABLE AGE
bbanews-deploy 3/3 3 3 15m

Check the load balancer IP through Azure portal: 

  • Navigate to Azure portal > Load Balancers > { workload cluster name }  > Frontend IP configuration.

 

Web page is accessible on Load balancer IP: 

 

Thanks for reading, Please write in below comments for any Queries.