Kubernetes - Basics


Prabhat Sharma


@hiprabhat
@prabhatsharma

Pod

pod.yaml - Definition

                
apiVersion: v1
kind: Pod
metadata:
  name: app1
  labels:
    app: person
spec:
  containers:
  - name: app1
    image: hiprabhat/ecommerce-person:v1
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"
      ports:
      - containerPort: 8080
                
              

$ kubectl apply -f pod.yaml

Multicontainer pod

multicontainer-pod.yaml - Definition

                
apiVersion: v1
kind: Pod
metadata:
  name: app1
  labels:
    app: person
spec:
  containers:
  - name: app1
    image: hiprabhat/ecommerce-person:v1
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"
        ports:
        - containerPort: 8080
  - name: product
    image: hiprabhat/product:v1
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"
      ports:
      - containerPort: 8081
                
              

$ kubectl apply -f multicontainer-pod.yaml

Inter pod communication

Replicaset

replicaset.yaml - Definition

                    
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: app1
spec:
  replicas: 3
  selector:
    matchLabels:
      app: person
  template:
    metadata:
      labels:
        app: person
    spec:
      containers:
      - name: person
        image: hiprabhat/ecommerce-person:v1
        imagePullPolicy: Always
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 8080
                    
                  

$ kubectl apply -f replicaset.yaml

Deployment

deployment.yaml Definition

                  
apiVersion: apps/v1
kind: Deployment
metadata:
  name: person
spec:
  replicas: 3
  selector:
    matchLabels:
      app: person
  template:
    metadata:
      labels:
        app: person
    spec:
      containers:
      - name: person
        image: hiprabhat/ecommerce-person:v1
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 8080
                  
                

$ kubectl apply -f deployment.yaml

Deployment - Update

Deployment - Update

Deployment - Update

Deployment - Update

Service

service.yaml Definition

                      
apiVersion: v1
kind: Service
metadata:
  name: person
spec:
  selector:
    app: person
  type: ClusterIP
  ports:
  - port: 8080
    targetPort: 80
                      
                    

$ kubectl apply -f service.yaml

Service - NodePort

Service - LoadBalancer

Thank You

Questions?