# services.yaml apiVersion:v1 kind:Service metadata: name:rollouts-demo-canary spec: ports: -port:80 targetPort:http protocol:TCP name:http selector: app:rollouts-demo # This selector will be updated with the pod-template-hash of the canary ReplicaSet. e.g.: # rollouts-pod-template-hash: 7bf84f9696
--- apiVersion:v1 kind:Service metadata: name:rollouts-demo-stable spec: ports: -port:80 targetPort:http protocol:TCP name:http selector: app:rollouts-demo # This selector will be updated with the pod-template-hash of the stable ReplicaSet. e.g.: # rollouts-pod-template-hash: 789746c88d
# services.yaml apiVersion:v1 kind:Service metadata: name:rollouts-demo-canary spec: ports: -port:80 targetPort:http protocol:TCP name:http selector: app:rollouts-demo # This selector will be updated with the pod-template-hash of the canary ReplicaSet. e.g.: # rollouts-pod-template-hash: 7bf84f9696
--- apiVersion:v1 kind:Service metadata: name:rollouts-demo-stable spec: ports: -port:80 targetPort:http protocol:TCP name:http selector: app:rollouts-demo # This selector will be updated with the pod-template-hash of the stable ReplicaSet. e.g.: # rollouts-pod-template-hash: 789746c88d
argo submit hello-world.yaml # submit a workflow spec to Kubernetes argo list # list current workflows argo get hello-world-xxx # get info about a specific workflow argo logs hello-world-xxx # print the logs from a workflow argo delete hello-world-xxx # delete workflow
apiVersion:argoproj.io/v1alpha1 kind:Workflow metadata: generateName:hello-world- labels: workflows.argoproj.io/archive-strategy:"false" annotations: workflows.argoproj.io/description:| This is a simple hello world example. You can also run it in Python: https://couler-proj.github.io/couler/examples/#hello-world spec: entrypoint:whalesay templates: -name:whalesay container: image:docker/whalesay:latest command: [cowsay] args: ["hello world"]
apiVersion:argoproj.io/v1alpha1 kind:Workflow metadata: generateName:arguments-parameters- spec: entrypoint:whalesay # Parameters can be passed/overridden via the argo CLI. # To override the printed message, run `argo submit` with the -p option: # $ argo submit examples/arguments-parameters.yaml -p message="goodbye world" arguments: parameters: -name:message value:helloworld
apiVersion:argoproj.io/v1alpha1 kind:Workflow metadata: generateName:global-parameters- spec: entrypoint:whalesay1 # Parameters can be passed/overridden via the argo CLI. # To override the printed message, run `argo submit` with the -p option: # $ argo submit examples/arguments-parameters.yaml -p message="goodbye world" arguments: parameters: -name:message value:helloworld
# This template demonstrates a steps template and how to control sequential vs. parallel steps. # In this example, the hello1 completes before the hello2a, and hello2b steps, which run in parallel. apiVersion:argoproj.io/v1alpha1 kind:Workflow metadata: generateName:steps- spec: entrypoint:hello-hello-hello templates: -name:hello-hello-hello steps: --name:hello1 template:whalesay arguments: parameters: [{name:message, value:"hello1"}] --name:hello2a template:whalesay arguments: parameters: [{name:message, value:"hello2a"}] -name:hello2b template:whalesay arguments: parameters: [{name:message, value:"hello2b"}]
# script templates provide a way to run arbitrary snippets of code # in any language, to produce a output "result" via the standard out # of the template. Results can then be referenced using the variable, # {{steps.<stepname>.outputs.result}}, and used as parameter to other # templates, and in 'when', and 'withParam' clauses. # This example demonstrates the use of a bash shell script to # generate a random number which is printed in the next step. apiVersion:argoproj.io/v1alpha1 kind:Workflow metadata: generateName:scripts-bash- spec: entrypoint:bash-script-example templates: -name:bash-script-example steps: --name:generate template:gen-random-int --name:print template:print-message arguments: parameters: -name:message value:"{{steps.generate.outputs.result}}"
# In this example we flip 2 times a coin. First time we # use the simple conditionals syntax. The second time we use # regex and a complex condition with logical AND and OR. # We also use of the parenthesis for defining the priority. apiVersion:argoproj.io/v1alpha1 kind:Workflow metadata: generateName:coinflip- spec: entrypoint:coinflip templates: -name:coinflip steps: # flip a coin --name:flip-coin template:flip-coin # evaluate the result in parallel --name:heads template:heads# call heads template if "heads" when:"{{steps.flip-coin.outputs.result}} == heads" -name:tails template:tails# call tails template if "tails" when:"{{steps.flip-coin.outputs.result}} == tails" --name:flip-again template:flip-coin --name:complex-condition template:heads-tails-or-twice-tails # call heads template if first flip was "heads" and second was "tails" OR both were "tails" when:>- ( {{steps.flip-coin.outputs.result}} == heads && {{steps.flip-again.outputs.result}} == tails ) || ( {{steps.flip-coin.outputs.result}} == tails && {{steps.flip-again.outputs.result}} == tails ) -name:heads-regex template:heads# call heads template if ~ "hea" when:"{{steps.flip-again.outputs.result}} =~ hea" -name:tails-regex template:tails# call heads template if ~ "tai" when:"{{steps.flip-again.outputs.result}} =~ tai"
# Return heads or tails based on a random number -name:flip-coin script: image:python:alpine3.6 command: [python] source:| import random result = "heads" if random.randint(0,1) == 0 else "tails" print(result) -name:heads container: image:alpine:3.6 command: [sh, -c] args: ["echo \"it was heads\""]
-name:heads-tails-or-twice-tails container: image:alpine:3.6 command: [sh, -c] args: ["echo \"it was heads the first flip and tails the second. Or it was two times tails.\""]
# coinflip-recursive is a variation of the coinflip example. # This is an example of a dynamic workflow which extends # indefinitely until it achieves a desired result. In this # example, the 'flip-coin' step is recursively repeated until # the result of the step is "heads". apiVersion:argoproj.io/v1alpha1 kind:Workflow metadata: generateName:coinflip-recursive- spec: entrypoint:coinflip templates: -name:coinflip steps: --name:flip-coin template:flip-coin --name:heads template:heads when:"{{steps.flip-coin.outputs.result}} == heads" -name:tails template:coinflip when:"{{steps.flip-coin.outputs.result}} == tails"
-name:flip-coin script: image:python:alpine3.6 command: [python] source:| import random result = "heads" if random.randint(0,1) == 0 else "tails" print(result) -name:heads container: image:alpine:3.6 command: [sh, -c] args: ["echo \"it was heads\""]
直到达成某个条件,workflow 才会跳出递归,然后结束;
和程序员开发过程中写循环一样,设定是否能正常退出递归的条件尤为关键,否则将会一直创建 POD 执行任务,直到超时或干预停止 workflow;
# An exit handler is a template reference that executes at the end of the workflow # irrespective of the success, failure, or error of the primary workflow. To specify # an exit handler, reference the name of a template in 'spec.onExit'. # Some common use cases of exit handlers are: # - sending notifications of workflow status (e.g. e-mail/slack) # - posting the pass/fail status to a webhook result (e.g. github build result) # - cleaning up workflow artifacts # - resubmitting or submitting another workflow apiVersion:argoproj.io/v1alpha1 kind:Workflow metadata: generateName:exit-handlers- spec: entrypoint:intentional-fail onExit:exit-handler templates: # primary workflow template -name:intentional-fail container: image:alpine:latest command: [sh, -c] args: ["echo intentional failure; exit 1"]
# exit handler related templates # After the completion of the entrypoint template, the status of the # workflow is made available in the global variable {{workflow.status}}. # {{workflow.status}} will be one of: Succeeded, Failed, Error -name:exit-handler steps: --name:notify template:send-email -name:celebrate template:celebrate when:"{{workflow.status}} == Succeeded" -name:cry template:cry when:"{{workflow.status}} != Succeeded" -name:send-email container: image:alpine:latest command: [sh, -c] # Tip: {{workflow.failures}} is a JSON list. If you're using bash to read it, we recommend using jq to manipulate # it. For example: # # echo "{{workflow.failures}}" | jq -r '.[] | "Failed Step: \(.displayName)\tMessage: \(.message)"' # # Will print a list of all the failed steps and their messages. For more info look up the jq docs. # Note: jq is not installed by default on the "alpine:latest" image, however it can be installed with "apk add jq" args: ["echo send e-mail: {{workflow.name}}{{workflow.status}}{{workflow.duration}}. Failed steps {{workflow.failures}}"] -name:celebrate container: image:alpine:latest command: [sh, -c] args: ["echo hooray!"] -name:cry container: image:alpine:latest command: [sh, -c] args: ["echo boohoo!"]
NAME STATUS ROLES AGE VERSION master1 Ready control-plane,master 56d v1.23.4 master2 Ready control-plane,master 56d v1.23.4 master3 Ready control-plane,master 56d v1.23.4
yum -y install epel-release wget make gcc openssl openssl-devel rrdtool rrdtool-perl perl-core perl mod_fcgid perl-CPAN httpd httpd-devel curl bind-utils gcc make vim gcc-c++ perl-LWP-Protocol-https wqy-microhei-fonts
2. 安装 fping
smokeping 2.7.2 以上需要 fping4.0 以上
1 2 3 4 5 6 7
cd /data/packages wget https://fping.org/dist/fping-4.2.tar.gz tar -zxvf fping-4.2.tar.gz cd fping-4.2 ./configure make make install
3. 安装 echoping
如果使用 tcp ping,需要它。
1 2 3 4 5 6 7 8
cd /data/packages wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz tar -zxvf echoping-6.0.2.tar.gz cd echoping-6.0.2 yum install -y popt-devel openssl openssl-devel ./configure --with-ssl --without-libidn make make install
4. 安装 smokeping
源码安装 smokeping 2.7.3。
1 2 3 4 5 6
cd /data/packages wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.7.3.tar.gz tar -zxvf smokeping-2.7.3.tar.gz cd smokeping-2.7.3 ./configure --prefix=/usr/local/smokeping /usr/bin/gmake install
cd /usr/local/smokeping mkdir var htdocs/{data,cache} chown apache.apache -R /usr/local/smokeping touch /var/log/smokeping.log chown apache.apache /var/log/smokeping.log cd /usr/local/smokeping/htdocs/ cp smokeping.fcgi.dist smokeping.fcgi chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
cat > /usr/local/smokeping/etc/config<<EOF *** General *** owner = admin contact = some@address.nowhere mailhost = my.mail.host sendmail = /usr/sbin/sendmail imgcache = /usr/local/smokeping/htdocs/cache imgurl = cache datadir = /usr/local/smokeping/htdocs/data piddir = /usr/local/smokeping/var cgiurl = http://10.10.23.103/smokeping/smokeping.fcgi smokemail = /usr/local/smokeping/etc/smokemail.dist tmail = /usr/local/smokeping/etc/tmail.dist # specify this to get syslog logging syslogfacility = local0 *** Alerts *** to = alertee@address.somewhere from = smokealert@company.xy +hostdown type = loss # in percent pattern = ==0%,==0%,==0%,==U comment = 对端无响应 +hightloss type = loss # in percent pattern = ==0%,==0%,==0%,==0%,>10%,>10%,>10% comment = 连续3次采样-丢包率超过10% +lossdetect type = loss # in percent pattern = ==0%,==0%,==0%,==0%,>0%,>0%,>0% comment = 连续3次采样-存在丢包 +someloss type = loss # in percent pattern = >0%,*12*,>0%,*12*,>0% comment = 间断性丢包 +rttdetect type = rtt # in milli seconds pattern = <100,<100,<100,<100,<100,<150,>150,>150,>150 comment = 连续3次采样延迟增大-超过150ms *** Database *** step = 60 pings = 20 # consfn mrhb steps total AVERAGE 0.5 1 1008 AVERAGE 0.5 12 4320 MIN 0.5 12 4320 MAX 0.5 12 4320 AVERAGE 0.5 144 720 MAX 0.5 144 720 MIN 0.5 144 720 *** Presentation *** charset = utf-8 template = /usr/local/smokeping/etc/basepage.html.dist htmltitle = yes graphborders = no + charts menu = Charts title = The most interesting destinations ++ stddev sorter = StdDev(entries=>4) title = Top Standard Deviation menu = Std Deviation format = Standard Deviation %f ++ max sorter = Max(entries=>5) title = Top Max Roundtrip Time menu = by Max format = Max Roundtrip Time %f seconds ++ loss sorter = Loss(entries=>5) title = Top Packet Loss menu = Loss format = Packets Lost %f ++ median sorter = Median(entries=>5) title = Top Median Roundtrip Time menu = by Median format = Median RTT %f seconds + overview width = 600 height = 50 range = 10h + detail width = 600 height = 200 unison_tolerance = 2 "Last 3 Hours" 3h "Last 30 Hours" 30h "Last 10 Days" 10d "Last 400 Days" 400d *** Probes *** + FPing binary = /usr/local/sbin/fping #可以设置源IP地址,适用于多IP的服务器,(比如组专线内网+公网)服务器 #sourceaddressn = 1.1.1.1 #*** Slaves *** #secrets=/usr/local/smokeping/etc/smokeping_secrets.dist #+aliyunShenzhen #display_name=slave1 #location=China #color=ff0000 # #+aliyunHangzhou #display_name=slave2 #location=China #color=ff00ff *** Targets *** probe = FPing menu = Top title = 网络质量监控系统 remark = 如果您是合法管理员,那么欢迎您,如果不是,请立即离开 Only legal administrators are welcome, if you are not, please leave immediately #加载额外的监控主机(将监控主机,单独成一个文件) @include targets EOF