Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排

Cloudify4.5.0和Kubernetes1.13.0进行混合容器编排demo

  • demo背景
  • Local Blueprint 的编写
  • 激动人心的时刻开始了,创建tomcat容器

demo背景

Cloudify4.5.0和Kubernetes1.13.0进行混合容器编排demo是基于前面两篇文章的环境而继续.
1.安装k8s1.13.0
2.安装Cloudify4.5.0
3.Cloudify对接K8s

Local Blueprint 的编写

1.点击Local Blueprint 然后点击Cloudify Composer
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第1张图片
2.然后就是编写它,点击Source
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第2张图片
tomcat8-5-cst.yml的内容如下:
有点需要注意:
1.这个镜像需要是配置自己的镜像仓库或者外网能拿的到的镜像:
image: ‘10.10.31.205/szy/tomcat8-5-cst:latest’
2.前面配置的K8s几个变量名,这里要引用的,注意名称要写对
eg:kubernetes_cloud_master_ip

tosca_definitions_version: cloudify_dsl_1_3
imports:
  - 'http://www.getcloudify.org/spec/cloudify/4.5/types.yaml'
  - 'plugin:cloudify-kubernetes-plugin'
inputs:
  kubernetes_master_configuration:
    default:
      apiVersion: v1
      kind: Config
      preferences: {}
      current-context: kubernetes-admin@kubernetes
      clusters:
        - name: kubernetes
          cluster:
            certificate-authority-data:
              get_secret: kubernetes_cloud_certificate_authority_data
            server:
              concat:
                - 'https://'
                - get_secret: kubernetes_cloud_master_ip
                - ':'
                - get_secret: kubernetes_master_port
      contexts:
        - name: kubernetes-admin@kubernetes
          context:
            cluster: kubernetes
            user: kubernetes-admin
      users:
        - name: kubernetes-admin
          user:
            client-certificate-data:
              get_secret: kubernetes-admin_cloud_client_certificate_data
            client-key-data:
              get_secret: kubernetes-admin_cloud_client_key_data
node_templates:
  kubernetes_master:
    type: cloudify.kubernetes.nodes.Master
    properties:
      configuration:
        file_content:
          get_input: kubernetes_master_configuration
    relationships: []
  App_deployment:
    type: cloudify.kubernetes.resources.Deployment
    properties:
      definition:
        apiVersion: extensions/v1beta1
        kind: Deployment
        metadata:
          name: container-demo
          labels:
            app: app-name-demo
            version: v1
        spec:
          selector:
            matchLabels:
              app: app-name-demo
              version: v1
          replicas: 1
          template:
            metadata:
              labels:
                app: app-name-demo
                version: v1
            spec:
              containers:
                - name: container-name-demo
                  image: '10.10.31.205/szy/tomcat8-5-cst:latest'
                  ports:
                    - containerPort: 8080
    relationships:
      - type: cloudify.kubernetes.relationships.managed_by_master
        target: kubernetes_master

Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第3张图片

Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第4张图片
upload后,在Local Blueprints能查看的到。
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第5张图片

激动人心的时刻开始了,创建tomcat容器

1.Deployment -create deployments
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第6张图片
创建时,可以选择Skip 跳过验证
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第7张图片
部署后,可以点击Deployments的名称,进去查看日志信息
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第8张图片
查看日志和事件信息
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第9张图片
日志信息:

11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Creating deployment work directory
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				'create_deployment_environment' workflow execution succeeded
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Using existing installation of managed plugin: da88c0cc-a7d4-4a9c-91a3-f0e5ce417dbe [package_name: cloudify-kubernetes-plugin, package_version: 2.3.2, supported_platform: linux_x86_64, distribution...
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Skipping starting deployment policy engine core - no policies defined
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Task succeeded 'cloudify_agent.operations.install_plugins'
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Using existing installation of managed plugin: da88c0cc-a7d4-4a9c-91a3-f0e5ce417dbe [package_name: cloudify-kubernetes-plugin, package_version: 2.3.2, supported_platform: linux_x86_64, distribution...
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Plugin path exists /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Plugin id path exists /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2/plugin.id
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Checking if managed plugin installation exists in /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Plugin id path exists /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2/plugin.id
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Checking if managed plugin installation exists in /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Plugin path exists /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Installing plugin kubernetes [current_platform=linux_x86_64, current_distro=centos, current_distro_release=core]
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Installing plugin kubernetes [current_platform=linux_x86_64, current_distro=centos, current_distro_release=core]
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Installing plugin: kubernetes
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				[localhost] run: ['/opt/mgmtworker/env/bin/pip', 'freeze', '--all']
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			[localhost] run: ['/opt/mgmtworker/env/bin/pip', 'freeze', '--all']
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Installing plugin: kubernetes
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Installing deployment plugins
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Task started 'cloudify_agent.operations.install_plugins'
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Sending task 'cloudify_agent.operations.install_plugins'
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Starting 'create_deployment_environment' workflow execution

然后选择 install 安装
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第10张图片
执行install
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第11张图片
这样就执行OK了,状态显示已经OK,我们来k8s里来看看
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第12张图片
k8s中已经有容器在创建了。
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第13张图片
OK, 现在k8s的容器已经创建OK。
Cloudify 学习(四):通过Cloudify的蓝图来创建第一个deployment,由k8s生成这个容器-容器编排_第14张图片

k8s上查看所有pods可以看的到结果。

[root@test01 ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE
default       container-demo-5984f9c774-rl4xv            1/1     Running   0          29m
kube-system   coredns-86c58d9df4-fpthk                   1/1     Running   0          4d17h
kube-system   coredns-86c58d9df4-pl9c8                   1/1     Running   0          4d17h
kube-system   etcd-test01.szy.local                      1/1     Running   0          4d17h
kube-system   kube-apiserver-test01.szy.local            1/1     Running   0          4d17h
kube-system   kube-controller-manager-test01.szy.local   1/1     Running   0          4d17h
kube-system   kube-flannel-ds-amd64-ltsmv                1/1     Running   0          39h
kube-system   kube-flannel-ds-amd64-mcwgp                1/1     Running   1          42h
kube-system   kube-flannel-ds-amd64-v8969                1/1     Running   0          44h
kube-system   kube-proxy-69c6s                           1/1     Running   0          39h
kube-system   kube-proxy-snq6k                           1/1     Running   0          4d17h
kube-system   kube-proxy-tq8dz                           1/1     Running   1          42h
kube-system   kube-scheduler-test01.szy.local            1/1     Running   0          4d17h
kube-system   kubernetes-dashboard-5877fb9459-8dcmc      1/1     Running   0          43h
kube-system   metrics-server-88584b494-fhpf7             1/1     Running   0          43h

另外:如果想在外部访问tomcat容器服务的话,需要修改下蓝图,创建service,然后通过ingress或者 外部流量访问k8s集群中service入口的一种方式(另一种方式是LoadBalancer),即nodeIP:nodePort是提供给外部流量访问k8s集群中service的入口.

下一篇文章会 ,继续更新

另外附上,Cloudify的deployments的创建日志:

12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Kubernetes API initialized successfully
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Node options {u'namespace': u'default'}
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Kubernetes API initialized successfully
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Kubernetes API initialized successfully
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Node options {u'namespace': u'default'}
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Configuration option FileContentConfiguration will be used
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Authentication option GCPServiceAccountAuthentication cannot be used
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Configuration option ManagerFilePathConfiguration cannot be used
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Cannot initialize Kubernetes API - no suitable configuration variant found for {} properties
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Checking Kubernetes authentication options
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Cannot initialize Kubernetes API - no suitable configuration variant found for {} properties
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Checking Kubernetes authentication options
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Authentication option GCPServiceAccountAuthentication cannot be used
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Configuration option BlueprintFileConfiguration cannot be used
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Configuration option ManagerFilePathConfiguration cannot be used
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Configuration option FileContentConfiguration will be used
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Configuration option BlueprintFileConfiguration cannot be used
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Checking how Kubernetes API should be configured
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Checking how Kubernetes API should be configured
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Sending task 'cloudify_kubernetes.tasks.resource_create'
12-12-2018 10:17	mydemo4tomcat	install	cloudify.interfaces.lifecycle.create	App_deployment	App_deployment_s8c76t	Task started 'cloudify_kubernetes.tasks.resource_create'
12-12-2018 10:17	mydemo4tomcat	install		App_deployment	App_deployment_s8c76t	Creating node
12-12-2018 10:17	mydemo4tomcat	install		kubernetes_master	kubernetes_master_xu1op0	Starting node
12-12-2018 10:17	mydemo4tomcat	install		kubernetes_master	kubernetes_master_xu1op0	Configuring node
12-12-2018 10:17	mydemo4tomcat	install		kubernetes_master	kubernetes_master_xu1op0	Creating node
12-12-2018 10:17	mydemo4tomcat	install				Starting 'install' workflow execution
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Creating deployment work directory
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				'create_deployment_environment' workflow execution succeeded
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Using existing installation of managed plugin: da88c0cc-a7d4-4a9c-91a3-f0e5ce417dbe [package_name: cloudify-kubernetes-plugin, package_version: 2.3.2, supported_platform: linux_x86_64, distribution...
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Using existing installation of managed plugin: da88c0cc-a7d4-4a9c-91a3-f0e5ce417dbe [package_name: cloudify-kubernetes-plugin, package_version: 2.3.2, supported_platform: linux_x86_64, distribution...
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Skipping starting deployment policy engine core - no policies defined
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Task succeeded 'cloudify_agent.operations.install_plugins'
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Checking if managed plugin installation exists in /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Plugin id path exists /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2/plugin.id
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Plugin path exists /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Plugin id path exists /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2/plugin.id
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Checking if managed plugin installation exists in /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Plugin path exists /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin-2.3.2
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Installing plugin kubernetes [current_platform=linux_x86_64, current_distro=centos, current_distro_release=core]
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Installing plugin kubernetes [current_platform=linux_x86_64, current_distro=centos, current_distro_release=core]
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Installing plugin: kubernetes
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				[localhost] run: ['/opt/mgmtworker/env/bin/pip', 'freeze', '--all']
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			[localhost] run: ['/opt/mgmtworker/env/bin/pip', 'freeze', '--all']
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment	,			Installing plugin: kubernetes
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Sending task 'cloudify_agent.operations.install_plugins'
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Task started 'cloudify_agent.operations.install_plugins'
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Installing deployment plugins
11-12-2018 22:20	mydemo4tomcat	create_deployment_environment				Starting 'create_deployment_environment' workflow execution

你可能感兴趣的:(Kubernetes,Cloudify,docker,Cloudify从入门到实践)