Deploy a workload using the CLI¶
MKE supports deploying your Kubernetes objects on the command line
using kubectl
.
Deploy an NGINX server¶
Create a file called
deployment.yaml
that contains the following content:apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 nodeSelector: kubernetes.io/os: linux --- apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: type: NodePort ports: - port: 80 nodePort: 32768 selector: app: nginx
Deploy the NGINX server:
kubectl apply -f deployment.yaml
Use the
describe deployment
option to review the deployment:kubectl describe deployment nginx-deployment
Update the deployment¶
Update an existing deployment by applying an updated YAML file.
Increase the number of replicas to 4:
kubectl scale --replicas=4 deployment/nginx-deployment
Update the NGINX version to 1.8:
kubectl set image deployment/nginx-deployment nginx=nginx:1.8
Deploy the updated NGINX server:
kubectl apply -f update.yaml
Verify that the deployment was scaled up successfully by listing the deployments in the cluster:
kubectl get deployments
Expected output:
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-deployment 4 4 4 4 2d
Verify that the pods are running the updated image:
kubectl describe deployment nginx-deployment | grep -i image
Expected output:
Image: nginx:1.8
See also