You can use the UCP web UI to deploy your Kubernetes YAML files. In most cases, modifications are not necessary to deploy on a cluster managed by Docker Enterprise.
In this example, a simple Kubernetes Deployment object for an NGINX server is defined in a YAML file.
apiVersion: apps/v1beta2
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
This YAML file specifies an earlier version of NGINX, which will be updated in a later section.
To create the YAML file:
The UCP web UI shows the status of your deployment when you click the links in the Kubernetes section of the left pane.
The NGINX server is up and running, but it’s not accessible from outside
of the cluster. Create a YAML file to add a NodePort
service to expose
the server on a specified port.
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 32768
selector:
app: nginx
The service connects the cluster’s internal port 80 to the external port 32768.
To expose the server:
Repeat the previous steps and copy-paste the YAML file that defines the
nginx
service into the Object YAML editor on the Create
Kubernetes Object page. When you click Create, the Load
Balancers page opens.
Click the nginx service, and in the details pane, find the Ports section.
Click the link that’s labeled URL to view the default NGINX page.
The YAML definition connects the service to the NGINX server using
the app label nginx
and a corresponding label selector.
Update an existing deployment by applying an updated YAML file. In this example, the server is scaled up to four replicas and updated to a later version of NGINX.
...
spec:
progressDeadlineSeconds: 600
replicas: 4
revisionHistoryLimit: 10
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx:1.8
...
From the left pane, click Controllers and select nginx-deployment.
In the details pane, click Configure, and in the Edit Deployment page, find the replicas: 2 entry.
Change the number of replicas to 4, so the line reads replicas: 4.
Find the image: nginx:1.7.9 entry and change it to image: nginx:1.8.
Click Save to update the deployment with the new YAML file.
From the the left pane, click Pods to view the newly created replicas.
With Docker Enterprise, you deploy your Kubernetes objects on the command line
using kubectl
.
Use a client bundle to configure your client tools, like Docker CLI and
kubectl
to communicate with UCP instead of the local deployments you
might have running.
When you have the client bundle set up, you can deploy a Kubernetes object from the YAML file.
apiVersion: apps/v1beta2
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
---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 32768
selector:
app: nginx
Save the previous YAML file to a file named “deployment.yaml”, and use the following command to deploy the NGINX server:
kubectl apply -f deployment.yaml
Use the describe deployment
option to inspect the deployment:
kubectl describe deployment nginx-deployment
Also, you can use the UCP web UI to see the deployment’s pods and controllers.
Update an existing deployment by applying an updated YAML file.
Edit deployment.yaml and change the following lines:
Save the edited YAML file to a file named “update.yaml”, and use the following command to deploy the NGINX server:
kubectl apply -f update.yaml
Check that the deployment was scaled out by listing the deployments in the cluster:
kubectl get deployments
You should see four pods in the deployment:
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx-deployment 4 4 4 4 2d
Check that the pods are running the updated image:
kubectl describe deployment nginx-deployment | grep -i image
You should see the currently running image:
Image: nginx:1.8