-
Notifications
You must be signed in to change notification settings - Fork 29
Kubernetes Objects
Syed Sayem edited this page Jan 5, 2020
·
8 revisions
A Deployment provides declarative updates for Pods and ReplicaSets.
You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.
Create a deployment-definition.yml
file
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container-pod
image: nginx
- Lets deploy some pod with deployment using yml file
kubectl create -f deployment-definition.yml
- Get list of replication controller
kubectl get deployments
- Get list of Pods
kuberctl get pods
In Kubernetes, there are three general approaches to exposing your application.
- Using a Kubernetes service of type NodePort, which exposes the application on a port across each of your nodes
- Use a Kubernetes service of type LoadBalancer, which creates an external load balancer that points to a Kubernetes service in your cluster
- Use a Kubernetes Ingress Resource
Read more on Medium
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: k8s.gcr.io/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /data
# this field is optional
type: Directory
- Get pod details of other namespace using:
kubectl get pods --namespace=dev
- By below command you will get pod details of default namespace
kubectl get pods
- You can change default namespace by using:
kubectl config set-context ${kubectl config current-context} --namespace=dev
- Now for getting pod details of default you need to use
kubectl get pods --namespace=default
- Get all pods details across namespaces using:
kubectl get pods --all-namespaces
- Creating a namespace using
yml
definition:
First, Create a namespace-dev.yml
file
apiVersion: v1
Kind: Namespace
metadata:
name: dev
Now, run the following command:
kubectl create -f namespace-dev.yml
- Mentioning namespace in pod:
kubectl create -f pod-definition.yml --namespace=dev
- Get list of system pods using:
kubectl get pods --namespace=kube-system
- You can set resource limits on namespaces, here an example yml for same:
apiVersion: 1
kind: ResourceQuota
metadata:
namespace: compute-quota
namespace: dev
spec:
hard:
pods: "10"
requests.cpu: "4"
requests.memory: 5Gi
limits.cpu: "10"
limits.memory: 10Gi
kubectl create -f compute-quota.yml