Categories
DevOps

Kubectl basic commands

kubectl get nodes
kubectl get deploy
kubectl get rs
kubectl get pods
kubectl get services
kubectl get all

YAML file

kubectl get deploy/[DEPLOYMENT_NAME] -o yaml 
kubectl get deploy [DEPLOYMENT_NAME] -o yaml 
kubectl get service/[SERVICES_NAME] -o yaml
kubectl get service [SERVICES_NAME] -o yaml

Deployment using YAML

kubectl create -f helloworld-deployment.yml
kubectl create -f helloworld-service.yml

helloworld-deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-deployment
spec:
  selector:
    matchLabels:
      app: helloworld
  replicas: 1 # tells deployment to run 1 pods matching the template
  template: # create pods using pod definition in this template
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image: karthequian/helloworld:latest
        ports:
        - containerPort: 80

helloworld-service.yml

apiVersion: v1
kind: Service
metadata:
  name: helloworld-service
spec:
  # if your cluster supports it, uncomment the following to automatically create
  # an external load-balanced IP for the frontend service.
  type: LoadBalancer
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: helloworld

Scale Application

kubectl scale --replicas=3 deploy/helloworld-deployment

Minikube

minikube service list
minikube service [SERVICE_NAME]