Deploy Kubernetes Objects

This section introduces that how you can deploy Kubernetes objects into multi environments and clusters.

KubeVela supports you to render, orchestrate and deploy Kubernetes objects. The common usage type is Deployment+Service. Using customized Workflow, you can deploy an application into multi-cluster in sequence. Hence you’ll get to know:

  1. Deploy Kubernetes objects.
  2. Workflow and its usage.
  3. Multi-env/cluster in application delivery.
  4. The control loop of application deployment: Rollback, Terminate and Continue.
  • Prepare Kubernetes Resources you want to deploy. In this guide, we’ll use a composition of Deployment and Service as example.

Below is a demo application with Kubernetes objects consist of Deployment and Service.

There are two policies and three workflow steps in it:

  • The policy means we’re going to deploy into two namespaces as different environments.
  • The workflow step means, we will deploy to one environment first, wait for human review after the first step succeeded, then finish the rest step.
  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: app-with-k8s-objects
  5. namespace: default
  6. spec:
  7. components:
  8. - name: k8s-demo-service
  9. properties:
  10. objects:
  11. - apiVersion: apps/v1
  12. kind: Deployment
  13. metadata:
  14. name: nginx
  15. spec:
  16. replicas: 2
  17. selector:
  18. matchLabels:
  19. app: nginx
  20. strategy:
  21. type: Recreate
  22. template:
  23. metadata:
  24. labels:
  25. app: nginx
  26. spec:
  27. containers:
  28. - image: nginx
  29. name: nginx
  30. ports:
  31. - containerPort: 80
  32. - apiVersion: v1
  33. kind: Service
  34. metadata:
  35. annotations:
  36. service.beta.kubernetes.io/aws-load-balancer-type: nlb
  37. labels:
  38. app: nginx
  39. name: nginx
  40. namespace: default
  41. spec:
  42. externalTrafficPolicy: Local
  43. ports:
  44. - name: http
  45. port: 80
  46. protocol: TCP
  47. targetPort: 80
  48. selector:
  49. app: nginx
  50. type: LoadBalancer
  51. type: k8s-objects
  52. policies:
  53. - name: topology-default
  54. type: topology
  55. properties:
  56. clusters: ['local']
  57. namespace: default
  58. - name: topology-production
  59. type: topology
  60. properties:
  61. clusters: ['local']
  62. namespace: production
  63. workflow:
  64. steps:
  65. - name: deploy2default
  66. properties:
  67. policies: ['topology-default']
  68. type: deploy
  69. - name: suspend
  70. type: suspend
  71. - name: deploy2production
  72. properties:
  73. policies: ['topology-production']
  74. type: deploy

Deploy this application by the following command:

  • You may need to create the namespace with the name production before deploying the application.
  1. vela up -f https://kubevela.io/example/applications/create-namespace.yaml
  • Deploy the demo application.
  1. vela up -f https://kubevela.io/example/applications/app-with-k8s-objects.yaml
  • Check the status of the application.
  1. vela status app-with-k8s-objects

You can also check the deployment and service with the kubectl or any other tools you familiar to check the deployment.

  • Approve the workflow if everything looks good.
  1. vela workflow resume app-with-k8s-objects

KubeVela also allows referring Kubernetes objects from Kubernetes cluster or remote URL links, so that you do not need to write Kubernetes objects inside Application directly. Read more about it in ref-objects.

We can do the same process in KubeVela UI Console if you have enabled velaux addon.

In VelaUX, we use Delivery Target to describe the space where the application resources actually delivered. It’s like syntax sugar to topology policy in UI console.

Refer to targets management doc for details and make sure you have 3 targets: 1 for test and 2 for prod environments for our below example.

After Target was created, we begin to create an application. Same to Deploy First Application, we need to submit basic Infos:

(1) Select type: k8s-objects; NOTE that in one application please maintain at most one Workload type of resource, meaning without more than a Deployment or Statefulset.

(2) We schedule two environments, test and prod. Test environment links to the target for dev and prod environment select the other two targets.

Deploy Kubernetes Objects - 图1

(3) Upload your Yaml file. Note that, the name of the resource you specified must not conflict with existing ones. Also, the editor automatically formats the Yaml file.

Deploy Kubernetes Objects - 图2

After above, click Create to finish.

Deploy Kubernetes Objects - 图3

Enter the further page, the application has automatically generated 2 environments and 2 workflows. Each environment has its workflow by default. A workflow consists of one or more steps such as deploy2env.

Firstly let’s switch to the Tab of the test environment, click Deploy on the page. Since we only assigned one target for the test environment, there’s one step for workflow. Looking at the status of its execution in the upper-right, it turns green when succeeded. If it shows red means that workflow went into trouble, you can click on the red sign to look through the detailed reason. Fix it accordingly and the deployment will continue to be regained.

After deployment is finished, refresh the list of instances to see Pods. Click for more if Pod shows abnormality.

Deploy Kubernetes Objects - 图4

As for the test environment, it sure can be updated at any time. When we update the parameters(image, instance), execute the workflow for an upgrade. Note that, choose the workflow for the test environment.

Deploy Kubernetes Objects - 图5

Let’s switch to the Tab of the prod environment. It shows that it’s not deployed yet. So now you can understand one basic thing for KubeVela, different environments in one application are completely dependant on each other, of each is an individual Application CR.

As we have two targets for the prod environment, it’ll execute in sequence. If you hope to set up a manual approval before it gets into the second target, this is where workflow comes in.

Deploy Kubernetes Objects - 图6

we can see two generated workflow. Now we click the Edit in the workflow of the prod environment, drag out the suspend into the board at the right. Set up the configuration you needed.

Then we need to orchestrate their sequence. First disconnect existing steps (by clicking the line + delete button), connect the suspend step in the middle. After editing, you need to click the Save button on the upper right to save.

Deploy Kubernetes Objects - 图7

Back to the page of prod environment, click Deploy.

Deploy Kubernetes Objects - 图8

Monitoring the status on the upper right. When the first target finished deploying, a window pops up for you to give out a command.

suspend has three operations:

  • Rollback: the revision reverts to the latest one in history, even with the first Target.
  • Terminate: stop the deployment process but it will not change the first Target that already deployed.
  • Continue: enter the execution of the next step.

If continued, the deployment goes on. In the list of instances, you can check out all the details.

Deploy Kubernetes Objects - 图9

Now you’ve learned how to deploy Kubernetes objects.

If you want to learn how to distribute resources across multi-clusters, you can refer to this doc.

Last updated on Feb 9, 2023 by dependabot[bot]