Tanzu: Kubernetes集群节点SSH登录
作者:互联网
SSH登录Tanzu Kubernetes集群节点进行日常运维排错
环境介绍:
NameSpace: tkc-cluster
https://www.icode9.com/i/l/?n=20&i=blog/1048291/202006/1048291-20200630190840044-1058379559.png
准备工作
创建名为 NAMESPACE 的环境变量,其值为 主管命名空间的名称。
export NAMESPACE=tkc-cluster
将上下文切换到置备了 主管命名空间集群的 Tanzu Kubernetes。
kubectl config use-context $NAMESPACE
运行以下 kubectl 命令以查看 YOUR-CLUSTER-NAME-ssh 密钥对象。
$ kubectl get secrets
NAME TYPE DATA AGE
default-token-qc2f8 kubernetes.io/service-account-token 3 10d
tkc-cluster-default-image-pull-secret kubernetes.io/dockerconfigjson 1 9d
tkc-cluster-default-image-push-secret kubernetes.io/dockerconfigjson 1 9d
tkc-guest-cluster-ca Opaque 2 8d
tkc-guest-cluster-ccm-token-kjw8d kubernetes.io/service-account-token 3 8d
tkc-guest-cluster-encryption Opaque 1 8d
tkc-guest-cluster-etcd Opaque 2 8d
tkc-guest-cluster-kubeconfig Opaque 1 8d
tkc-guest-cluster-proxy Opaque 2 8d
tkc-guest-cluster-pvcsi-token-mcd5g kubernetes.io/service-account-token 3 8d
tkc-guest-cluster-sa Opaque 2 8d
tkc-guest-cluster-ssh kubernetes.io/ssh-auth 1 8d
tkc-guest-cluster-ssh-password Opaque 1 8d
jumpbox.yaml
apiVersion: v1
kind: Pod
metadata:
name: jumpbox
namespace: tkc-cluster #REPLACE YOUR-NAMESPACE
spec:
containers:
- image: "photon:3.0"
name: jumpbox
command: [ "/bin/bash", "-c", "--" ]
args: [ "yum install -y openssh-server openssh-clients; mkdir /root/.ssh; cp /root/ssh/ssh-privatekey /root/.ssh/id_rsa; chmod 600 /root/.ssh/id_rsa; while true; do sleep 30; done;" ]
volumeMounts:
- mountPath: "/root/ssh"
name: ssh-key
readOnly: true
volumes:
- name: ssh-key
secret:
secretName: tkc-guest-cluster-ssh #REPLACE YOUR-CLUSTER-NAME
获取节点IP
$ kubectl get virtualmachine
NAME AGE
tkc-guest-cluster-control-plane-6cfsf 8d
tkc-guest-cluster-control-plane-drlqp 8d
tkc-guest-cluster-control-plane-wmn2s 8d
tkc-guest-cluster-workers-8k9c8-5576b69b67-rcsvd 29h
tkc-guest-cluster-workers-8k9c8-5576b69b67-s7hch 8d
tkc-guest-cluster-workers-8k9c8-5576b69b67-sb6ss 29h
tkc-guest-cluster-workers-8k9c8-5576b69b67-tnxn2 8d
tkc-guest-cluster-workers-8k9c8-5576b69b67-vxgt9 8d
$ VMNAME=tkc-guest-cluster-control-plane-wmn2s
$ export VMIP=$(kubectl -n $NAMESPACE get virtualmachine/$VMNAME -o jsonpath='{.status.vmIp}')
执行SSH
$ kubectl apply -f jumpbox.yaml
$ kubectl exec -it jumpbox /usr/bin/ssh vmware-system-user@$VMIP
... 恭喜SSH登录成功
标签:Tanzu,guest,Kubernetes,Opaque,8d,cluster,SSH,ssh,tkc 来源: https://www.cnblogs.com/shunzi115/p/14988772.html