【发布时间】:2020-04-24 19:16:48
【问题描述】:
我需要一些帮助才能知道我在这里缺少什么.. 我正在尝试从自定义 values.yml 文件为我的实验室 (localhost-master) 部署流集应用程序。我正在尝试在 "streamset-ns" 命名空间上部署 pod。我面临以下错误。 stderr:在 streamset-ns 命名空间中找不到资源。
任务下的主脚本
- name: Listing all Namespaces
command: "kubectl get namespaces"
register: namespace_list
- name: Checking if streamsets is installed in "{{streamsets_namespace}}"
command: "kubectl get pods -n {{streamsets_namespace}}"
register: if_streamsets
- set_fact:
message: "{{ ((task_type == 'install') and ('deployed' in if_streamsets.stdout)) or ((task_type == 'uninstall') and ('deployed' in if_streamsets.stdout)) | ternary('streamsets is installed', 'streamsets is not installed') }}"
- debug:
msg: "{{message}}"
- name: Checking streamsets running status
block:
- debug:
msg: "streamsets is already deployed in {{streamsets_namespace}}"
- name: Getting deployed pod status
command: "kubectl get pods -n {{streamsets_namespace}}"
register: streamsets_pod_status
- debug:
var: streamsets_pod_status.stdout_lines
when: "'streamsets' in if_streamsets.stdout and 'deployed' in if_streamsets.stdout"
- name: Installing streamsets
block:
- name: Create a Kubernetes namespace for streamsets
k8s:
name: "{{streamsets_namespace}}"
api_version: v1
kind: Namespace
state: present
when: "streamsets_namespace not in namespace_list.stdout_lines"
# - name: Adding Helm Repository for Streamsets
# command: "{{helm_location}}/helm repo add streamsets {{streamsets_helm_charts}}"
# register: helm_repo_results
# changed_when: False
# failed_when: "'Error' in helm_repo_results.stderr"
#
- name: Applying Template Module
template:
src: "roles/streamsets/templates/values.yml.j2"
dest: "/home/{{ansible_user}}/values.yml"
mode: '0644'
- name: Install streamsets using Command Module
command: "kubectl create -f /home/{{ansible_user}}/values.yml -n {{streamsets_namespace}}"
register: streamsets_result
failed_when: "'Error' in streamsets_result.stderr"
- debug:
var: streamsets_result.stdout_lines
# - name: Checking Streamsets Deployment Status
# action:
# shell kubectl get pods -n "{{streamsets_namespace}}"| grep "{{streamsets_release_name}}" | grep '1/1' |wc -l
# register: streamsets_deployment_status
# until: streamsets_deployment_status.stdout|int == streamsets_replicas | int
# retries: 5
# delay: 60
#
# - debug:
# var: streamsets_deployment_status.stdout_lines
- name: Checking Streamsets Deployment Status
command: kubectl -n "{{streamsets_namespace}}" wait --for=condition=Ready pods --all --timeout=180s
register: Streamsets_pod_status
failed_when: "'Error' in Streamsets_pod_status.stderr"
- name: Removing deployed configuration files for Streamsets
file:
path: "/home/{{ansible_user}}/values.yml"
state: absent
when: "'install' == task_type and 'streamsets' not in if_streamsets.stdout and 'deployed' not in if_streamsets.stdout"
- name: Unistalling streamsets from K8s
block:
- name: Removing Statefulsets & Service from "{{streamsets_namespace}}"
action:
shell kubectl -n "{{streamsets_namespace}}" delete statefulsets "{{streamsets_release_name}}" && kubectl -n "{{streamsets_namespace}}" delete service "{{streamsets_release_name}}"-service
register: streamsets_removal_status
- debug:
var: streamsets_removal_status.stdout_lines
# - name: Checking PVC status in "{{streamsets_namespace}}"
# shell: kubectl get pvc -n "{{streamsets_namespace}}" | grep -v NAME | cut -d ' ' -f1
# register: streamsets_pvc_status
# - debug:
# var: streamsets_pvc_status.stdout_lines
# - name: Delete occupied pvc for streamsets
# command: "kubectl delete pvc -n {{streamsets_namespace}} {{streamsets_pvc_status.stdout}}"
# register: pvc_delete_status
# when: streamsets_pvc_status.stdout_lines != ''
# - debug:
# var: pvc_delete_status.stdout_lines
when: "'uninstall' == task_type and 'streamsets' in if_streamsets.stdout and 'deployed' in if_streamsets.stdout"
- name: Playbook Signature
block:
- debug:
msg: "No 'task_type' supplied. Playbook signature: ansible-playbook -i <hosts file> <playbook> --extra-vars 'task_type=<install/uninstall>'"
when: "task_type == '' or ('install' or 'uninstall') not in task_type"
在模板下创建的yml
---
apiVersion: v1
kind: Service
metadata:
name: streamsets-service
labels:
name: streamsets
spec:
type: NodePort
ports:
- port: {{streamsets_port}}
targetPort: 18630
nodePort: {{streamsets_nodePort}}
selector:
role: streamsets
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: streamsets
spec:
serviceName: streamsets-service
replicas: {{streamsets_replicas}}
selector:
matchLabels:
name: streamsets
template:
metadata:
labels:
role: streamsets
environment: test
replicaset: streamsetsRepSet
spec:
terminationGracePeriodSeconds: 10
containers:
- name: {{streamsets_image_container}}
image: {{streamsets_image_name}}:{{streamsets_image_version}}
imagePullPolicy: Always
ports:
- containerPort: 18630
volumeMounts:
- name: data
mountPath: /data
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: {{streamsets_storageClass}}
resources:
requests:
storage: {{streamsets_storage_volume}}
你能帮帮我吗?
【问题讨论】:
-
您好,您开始检查命名空间是否已经有一些 pod:
...Checking if streamsets is installed in ..但是如果没有 pod,您将收到如下错误:kubectl -n foo get pods No resources found in foo namespace.同样为了您的 Ansible-Playbook 改进,您可以直接在 k8s Ansible-Module 中使用该模板:- name: Read definition file from the Ansible controller file system after Jinja templating k8s: state: present definition: "{{ lookup('template', '/testing/deployment.yml') }}"Maybee 您也可以告诉我们,您的 Playbook 哪里失败了? -
@CLNRMN - 我在安装 Streamset 时遇到的错误是 -
The StatefulSet \"streamsets\" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{\"environment\":\"test\", \"replicaset\":\"streamsetsRepSet\", \"role\":\"streamsets\"}:selector` 与模板 `labels` 不匹配
标签: kubernetes kubernetes-pod streamsets kubernetes-statefulset