Pods:
- pods are the small deployment unit in k8s (which will run the container in k8s)
keypoints:
- A pod is the atomic unit in k8s cluster
- Every pod will have its own ipaddress
- contained having some shared componets
- networking
- shared storage
- every container having its bown cpu, memory.
method to deploy pod in k8s cluster
- imperative method
kubectl run nginx --image=nginx --restart=Never
- Declerative method
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
restartPolicy: Always
Access pod from locally
kubectl port-forward <resource-type>/<name> [local-port]:<remote-port>
kubectl port-forward pod/nginx-app 80:80
K8s api referances
- step 1 need chose type resource creating
- api version resource
- kind (type of api version resource name)
Sample for pod manfest
- apiVersion string APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
- kind string Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
- metadata ObjectMeta Standard object’s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
- spec PodSpec Specification of the desired behavior of the pod. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
- status PodStatus Most recently observed status of the pod. This data may not be up to date. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
apiVersion:
kind:
metadata:
spec:
status:
Task
- setup k8s cluster
- deploy sample pod and access port-farward cmd
- Try deploy deployment yaml file
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
kubectl apply -f sample.yaml
kubectl delete pods --all
