apiVersion: v1
kind: Pod
metadata:
name: my-nginx
spec:
containers:
- name: my-nginx
image: nginx:alpine
Create a deployment
k create -f deployment_a.yml
Create or update a deployment with the ability to apply changes afterward.
k create -f mypod.yaml --save-config
The same as create --save-config
but also for updating.
k apply -f deployment_a.yml
Create a new service that expose the deployment to the outside through a specificed port.
k expose deployment -f deployment_a.yml --type=NodePort --port=80 --name=nginxexpose
k delete -f deployment_a.yml
A servcie is a server instance that has static ip in the deployment and connect and allow access to nodes from outside or other nodes.
Needed because nodes are ephemerical and has ip which is not constant.
A service that gets a cluster ip that is exposed only within the cluster. It is used to talk and connect between pods in the same cluster.
A service that is exposed to the outside of the cluster by all the cluster nodes at a specific port. Outside party can communicate with the service throguth the node ip + the port. That communication is then redirected to the service, which in turn redirect it to the relevant pods it handles.
A service that handle communication to an external party. This allow elements in the cluster to not know the details of the external party and encapsulate that logic in the external name service. When the communication details of the external party changes, only the external name service needed to be updated with that information.
Create temporary tunnel which allow connection between the outside and the inside of a cluster.
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#port-forward https://stackoverflow.com/questions/51468491/how-kubectl-port-forward-works
Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
kubectl port-forward pod/mypod 5000 6000
Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the deployment
kubectl port-forward deployment/mydeployment 5000 6000
apiVersion: v1
kind: Service
metadata:
name: nginx-clusterip
spec:
type: ClusterIP
selector:
app: my-nginx
ports:
- port: 8080
targetPort: 80
apiVersion: v1
kind: Service
metadata:
name: nginx-nodeport
spec:
type: NodePort
selector:
tier: frontend
ports:
- port: 80
targetPort: 80
nodePort: 31000
apiVersion: v1
kind: Service
metadata:
name: nginx-loadbalancer
spec:
type: LoadBalancer
selector:
tier: frontend
ports:
- name: "80"
port: 80
targetPort: 80
- Tied to the pod lifecycle. Goes away when the pod goes away.
- Used to share data between containers in the same pod.
- Tied to the node lifecycle. Goes away when the node goes away.
Network file system. The pod access an external shared network storage access.