-
Notifications
You must be signed in to change notification settings - Fork 29
Kubernetes Objects
Syed Sayem edited this page Jan 5, 2020
·
8 revisions
- Lets deploy a pod using:
kubectl run nginx
This command will only deploy a Pod on your kubernetes worker node without any container inside it
- Now lets deploy a pod with a Nginx container
kubectl run nginx --image nginx
This command will only deploy a Pod on your kubernetes worker node with nginx container inside it
- Get running pod list using
kubectl get pod
- Get running pod details using:
kubectl describe pod <pod-name>
- Delete pod using
kubectl delete pod <pod-name>
- Now lets try to deploy pod with its container using YAML file
Create a pod-definition.yml
file
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
name: myapp-pod
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
Deploy using following command
kubectl create -f pod-definition.yml
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