This topic describes how to deploy a service.
Prerequisites
Before you deploy a service, make sure that you have performed the following operations:
Background information
In a phased release or a blue-green deployment, you can run the new version of a service
in an environment identical to the environment where the earlier version of the service
runs. You can set a rule to direct some traffic that is destined for the earlier version
to the new version without interrupting the earlier version. After the new version
runs properly for a period of time, you can direct all traffic to the new version.
This topic describes how to deploy a service of an earlier version.
Procedure
- Log on to the ACK console.
- In the left-side navigation pane, click Clusters.
- On the Clusters page, click the name of a cluster or click Details in the Actions column. The details page of the cluster appears.
- In the left-side navigation pane, click Workload.
- Select the Deployments tab.
- In the upper-right corner of the Deployments tab, click Create from Template
- Select a sample template or use an existing template, and click Create.
In this example, a template is orchestrated to deploy an Nginx application that contains
the deployment, the service, and an Ingress. The deployment exposes its port through
NodePort. The Ingress provides externally accessible services. The following content
is a sample template:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: old-nginx
spec:
replicas: 2
selector:
matchLabels:
run: old-nginx
template:
metadata:
labels:
run: old-nginx
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/xianlu/old-nginx
imagePullPolicy: Always
name: old-nginx
ports:
- containerPort: 80
protocol: TCP
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: old-nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: old-nginx
sessionAffinity: None
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gray-release
spec:
rules:
- host: www.example.com
http:
paths:
# Earlier version of the service
- path: /
backend:
serviceName: old-nginx
servicePort: 80
- In the left-side navigation pane, click Ingresses.
You can see that the virtual host name points to old-nginx.
- Log on to a master node of the cluster. Then, use curl to run the following command
to send requests to the ingress:
curl -H "Host: www.example.com" http://<EXTERNAL_IP>
Note You can obtain the value of
<EXTERNAL_IP>
by using either of the following methods:
- Run the following command:
kubectl get ingress
- Log on to the Container Service-Kubernetes console, click the cluster name on the
Clusters page. In the left-side navigation pane, click Ingresses to view the endpoint information of the Ingress.