Kubernetes – Classroom series – 17/Oct/2019

How to access multiple Pods from outside cluster

Networking

Pod Communication with in node

Preview

Pod Communications across nodes

Preview

Service

Preview

Sample Service yaml

---
apiVersion: v1
kind: Service
metadata:
  name: tomcat-svc
spec:
  selector:
    app: tomcat
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
    nodePort: 30001
  type: NodePort

  • Run a service which exposes Whatever is running on Port 8080 on Pod to 30001 on the node
  • Types of Exposing the Servcies
    • Node Port
    • Load Balancer: Natively can be run on cloud providers

Ingress

  • Ingress is much like load balancer, but it is layer 7 load balancing
  • It is application layer, which means it is http & https aware
  • When Ingress is linked with DNS services, you can access Pods by DNS names

Deployment

  • Controller for rolling out the deployments & undoing deployments
apiVersion: apps/v1
kind: Deployment
metadata:
  # Unique key of the Deployment instance
  name: deployment-example
spec:
  # 3 Pods should exist at all times.
  replicas: 3
  selector:
    matchLabels:
      app: tomcat
  template:
    metadata:
      labels:
        # Apply this label to pods and default
        # the Deployment label selector to this value
        app: tomcat
    spec:
      containers:
      - name: tomcat
        # Run this image
        image: tomcat:8
        ports:
          - containerPort: 8080
            protocol: TCP
  • Execute
# first attempt
kubectl apply -f deploy.yml
kubectl get deployments
kubectl get rs
  • Make changes to YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  # Unique key of the Deployment instance
  name: deployment-example
spec:
  # 3 Pods should exist at all times.
  replicas: 3
  selector:
    matchLabels:
      app: tomcat
  template:
    metadata:
      labels:
        # Apply this label to pods and default
        # the Deployment label selector to this value
        app: tomcat
    spec:
      containers:
      - name: tomcat
        # Run this image
        image: tomcat:9
        ports:
          - containerPort: 8080
            protocol: TCP
  • Execute the following commands
kubectl apply -f deploy.yaml --record
kubectl get deployments
kubectl rollout status deployments deployment-example
kubectl rollout history deployments deployment-example
  • If you look at history, every deployment has a revision. You can go back to earlier revisions
kubectl rollout undo deployments deployment-example --to-revision=1
  • Note: use above example with svc enabled.

Next steps

  • Storage
  • Configurations
  • Cloud Native K8S

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner