apiVersion: karpenter.sh/v1alpha5 kind: Provisioner metadata: name: default spec: requirements: - key: karpenter.sh/capacity-type operator: In values: ["spot"] limits: resources: cpu: 1000 providerRef: name: default ttlSecondsAfterEmpty: 30 --- apiVersion: karpenter.k8s.aws/v1alpha1 kind: AWSNodeTemplate metadata: name: default spec: subnetSelector: karpenter.sh/discovery: ec2-user-karpenter-demo securityGroupSelector: karpenter.sh/discovery: ec2-user-karpenter-demo userData: | MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="BOUNDARY" --BOUNDARY Content-Type: text/x-shellscript; charset="us-ascii" #!/bin/bash mkdir -p ~ec2-user/.ssh/ touch ~ec2-user/.ssh/authorized_keys echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDh+ZlBtS9IJ9L17Ug8CdEYE80MkXvX8FYQd0dfyJ/kx/rY7Pt1V6tI0kKegcyPQXDNWspLBq9Hs4SyFiT/6RjKJAz0hHbrWkny7QSA7xzTALv0is/kM+m5vXJYtSKatV1TmunS6QZU52mxzPj+lrE71lbEDqV4Mq5u7/UhdjA3mACqL8N+ltpn8/AmO7wkvUEzANznqRNqlyZo5uvwOsi9WywFGkS7ZDUdweKwaxVfGWisEn/dZ8ch3y1PB/tirhjc+ch9BksssgSPj0+cPZ+F+Mx+Q3NaLVT729JWen2Ju2l/hCskw7vNHynIYFUiBFvwXZG8WNWJ1d8T5WxVgfoh ec2-user@ip-172-31-33-205.ap-southeast-1.compute.internal" >> ~ec2-user/.ssh/authorized_keys chmod -R go-w ~ec2-user/.ssh/authorized_keys chown -R ec2-user ~ec2-user/.ssh --BOUNDARY--
import paramiko key = paramiko.RSAKey.from_private_key_file("./id_rsa") ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) print("connecting") ssh.connect(hostname="192.168.146.197", username="ec2-user", pkey=key) print("connected") commands = "journalctl" stdin, stdout, stderr = ssh.exec_command(commands) stdin.close() res, err= stdout.read(), stderr.read() result= res if res else err print(result) ssh.close()
标签:karpenter,ec2,user,key,test,paramiko,ssh From: https://www.cnblogs.com/yiqiangchuanyun/p/16774265.html