阅读量:0
1.首先安装kubectl
1.1验证自己系统
uname -m
1.2
按照步骤安装
在 Linux 系统中安装并设置 kubectl | Kubernetes
1.3 阿里云配置
通过kubectl连接Kubernetes集群_容器服务 Kubernetes 版 ACK(ACK)-阿里云帮助中心
2.验证
阿里云config直接导出,直接扔到.kube/ 位置也行
mkdir ~/.kube/ cd ~/.kube/ vim config kubectl get node,pod,svc
3.1 多config配置
//合并配置 KUBECONFIG=$HOME/.kube/config_latest:$HOME/.kube/config_qa kubectl config view --merge --flatten > config //永久生效 echo 'export KUBECONFIG=$HOME/.kube/config' >> ~/.bashrc source ~/.bashrc //查看当前配置 kubectl config current-context kubectl config get-contexts
3.2 合成config事例
apiVersion: v1 clusters: - cluster: certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURUakNDQWphZ0F3SUJBZ0lVU1dWMW5XdEd0Q0FGcmxU3RUdi9PRUZ3cWtXWHRaZ3NlcEMxNUlURW4234234234l5OGUyTHZtSFBTMjhWa0NQenhkCkVaK0l0SEhQUHp2TU4zTGxZeFZiL0lXWnVtQzhCbFhHSmxRbDJER1J3OEJjWXFGUWpySGx2TXV3NnhOUmVzeVoKY1lCOEY0Q0pjUUczRzdTQTFERkpCdmRIMm1ZTGkyZTIrNEUvc05KZG5hdElqajUwTm5KT3VUWHRGc0JRb1E2ZgozVk45NmFsaWFlM1pmNGM3Wkw4aFh0WXdjUkdmS292TVpnVkoxRytOdnRXajNnPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= server: https://4.1.1.4:6443 name: latest - cluster: certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURUakNDQWphZ0F3SUJBZ0lVQ04yNXQxM0V1WGhxNTdZZ0d0U1l4TTlINDl3d0RRWUpLb1pJaHZjTkFRRUwKQlFBd1BqRW5NQThHQTFVRUNoTUlhR0Z1WjNwb2IzVXdGQVlEVlFRS0V3MWhiR2xpWVdKaElHTnNiM1ZrTVJNdwpFUVlEVlFRREV3cHJkV0psY201bGRHVnpNQ0FYRFRJek1EZ3lOREF5TWpBd01Gb1lEekl3TlRNd09ERTJNREl5Ck1EQXdXakErTVNjd0R3WURWUVFLRXdob1lXNW5lbWh2ZFRBVUJnTlZCQW9URFdGc2FXSm423423hZbUVnWTJ4dmRXUXgKRXpBUkJnTlZCQU1UQ210MVltVnlibVYwWlhNd2dnRczJJdHFCcHVGOSsrdVdIQ0x5MnpkCjZvZmlRUndxYWpVOFNqTkxvZnpSYm13MVA5NXNER1EzTlMvajNWUUVFc25aV0laNnJFQXYvcndUMVpKMVFCM2QKUVkvRW1uREp5djFlc1owYUxMOGcxeU92QnY5TVRJM2lWWjJIUDZKTXZaNFE3Q3VZQWc5RkowMWtRNGg3NkpDegpTZERHcXovcGhMZDVCcFBzRmZZZDduRmM3WDhHL0NNUVlKNWo1N3hOVWJJbkJ3PT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= server: https://7.1.31:6443 name: qa contexts: - context: cluster: qa user: "204665595022800847-c216c8c771a6441f78dd51d0bc8923837" name: 204665595022800847-c216c8c771a6441f78dd51d0bc8923837 - context: cluster: latest user: "204665595022800847-c6cb2271ee11946efb633f6f0e8ee1dc1" name: 204665595022800847-c6cb2271ee11946efb633f6f0e8ee1dc1 current-context: 204665595022800847-c216c8c771a6441f78dd51d0bc8923837 kind: Config preferences: {} users: - name: "204665595022800847-c6cb2271ee11946efb633f6f0e8ee1dc1" user: client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUQvekNDQXVlZ0F3SUJBZ0lFQVhBd1ZUQU5CZ2txaGtpRzl3MEJBUXNGQURCcU1Tb3dLQVlEVlFRS0V5RmoKTm1OaU1qSTNNV1ZsTVRFNU5EWmxabUkyTXpObU5tWXdaVGhsWlRGa1RUJBTUNCNEF3RXdZRFZSMGxCQXd3CkNnWUlLd1lCQlFVSEF3SXdEQVlEVlIwVEFRSC9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