Wednesday, January 13, 2021

Kubernetes - Services creating POD and Services - Day 6

 1/13/2021

Kubernetes Service
yaml code for load balancer


> kc get services
> kc get svc


$ cat svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: mylb1
spec:
  selector:
    app: web
  ports:
    - targetPort: 80
      port: 8080

> kc apply -f svc.yaml

> kc get svc
> kc describe svc mylb1

Output has no endpoint.
behind loadbalancer, there is no end point. or backend.

> kc get pods
no pod running.

now, launch a pod using pod definition file

$ cat mypod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: "mypod1"
  labels:
    app: web

spec:
  containers:
  - name: "myc1"
    image: "dimple12/apache-webserver-php"

> kc apply -f pod.yaml

> kc get pods
> kc get pods -L app
> kc describe svc mylb1


-----------------------------------


apiVersion: v1
kind: Pod
metadata:
  name: "mypod2"
  labels:
    app: web

spec:
  containers:
  - name: "myc1"
  image: "dimple12/apache-webserver-php"


> kc apply -f pod.yaml

> kc get pods
> kc get pods -L app
> kc describe svc mylb1


now IP is displayed - end point
> kc describe pods mypod2


luanch pod with new name ..

apiVersion: v1
kind: Pod
metadata:
  name: "mypod3"
  labels:
    app: web

spec:
  containers:
  - name: "myc1"
    image: "dimple12/apache-webserver-php"


> kc apply -f pod.yaml

> kc get pods
> kc get pods -L app
> kc describe svc mylb1


$ cat svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: mylb1
spec:
  type: NodePort
  selector:
    app: web
  ports:
    - targetPort: 80
      port: 8080
      nodePort: 30000



> kc get svs
kc apply -f svc.yaml

kc get svc
> kc describe svc mylb1

you see end point is available


now expose


go to windows and run

Ip is node IP and you are exposing the port.

curl https://192.168.99.100:30000

you get a page..



keywords:
replication controller - helps you to create replicas such as 4, 5 ports
load balancer
NodePort
Selector
targetport
clusterIP
external
exposed
service (load balancer)
deployment




cloud.creynold.net

No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...