Kubertenetes usa un fichero de configuración llamado Kubernetes Deployment Object, donde describimos en formato YAML el despliegue a realizar.
un ejemplo del mismo sería el siguiente fichero nginx-despliegue.yaml <sxh yaml> apiVersion : apps/v1 kind: Deployment metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metada:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort:80
</sxh>
Para realizar este despliegue ejecutaríamos en el manager <sxh>kubectl apply -f nginx-despliegue.yaml</sxh>
Para comprobar lo que ha realizado ejecutaríamos <sxh>kubectl deescribe deployment nginx-despliegue</sxh>
Para comprobar los pods <sxh>kubectl get pods -l app=nginx</sxh> <sxh>kubectl describe pod nginx-despliegue-75654585</sxh>
Para quitar el despliegue <sxh>kubectl delete deployment nginx-despliegue</sxh>
Vamos a desplegar un servidor NGINX directamente
<sxh>kubectl create deployment nginx –image=nginx </sxh>
<sxh>kubectl create service nodeport nginx –tcp=80:80</sxh>
<sxh>kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4m nginx NodePort 10.96.25.233 <none> 80:32746/TCP 6s</sxh>
Finalmente,abrimos nuestro navegador y conectamos a la url http://xxx.xxx.xxx:32746 (IP del nodo manager:puerto por donde lo expone). Al conectar desde el navegador deberías de ver la imagen de bienvenida del servidor ngnix