从零完成k3s Kubeconfig配置( 二 )

它将创建一个kubeconfig文件并且保存在你运行命令的目录中 。
步骤4:导出KUBECONFIG
[root@ip-172-31-33-136 bin]#** export KUBECONFIG=`pwd`/kubeconfig**步骤5:开始玩转k3s
[root@ip-172-31-33-136 bin]# **./kubectl get nodes**NAME STATUS ROLES AGE VERSIONip-172-31-33-136.ec2.internal Ready master 24s v1.14.5-k3s.1[root@ip-172-31-33-136 bin]# **./kubectl get pods -n kube-system**NAME READY STATUS RESTARTS AGEcoreDNS-b7464766c-ngf46 1/1 Running 0 4m3shelm-install-traefik-x6wfj 0/1 Completed 0 4m3ssvclb-traefik-65Gw9 2/2 Running 0 3m49straefik-56688c4464-5rdss 1/1 Running 0 3m49s运行一个简单的服务:
# Create a Deployment**./kubectl run Nginx --image=nginx**# Create Service[root@ip-172-31-33-136 bin]# **./kubectl expose deployment nginx --port=80 --target-port=80**service/nginx exposed[root@ip-172-31-33-136 bin]# **./kubectl get svc**NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 10.43.0.1 <none> 443/TCP 45mnginx ClusterIP 10.43.99.179 <none> 80/TCP 5s[root@ip-172-31-33-136 bin]# **curl 10.43.99.179**<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.</p><p>For online documentation and support please refer to<a href=https://www.isolves.com/it/cxkf/bk/2019-08-28/"http://nginx.org/">nginx.org.
Commercial support is available atnginx.com.

Thank you for using nginx.

加入两个节点:是否可以在不登录节点的情况下将节点与主节点连接?是的,k3sup可以做到这一点 。
在VM上获得k3s设置后,你可以轻松地将节点加入到集群:
#AGENT_IP is the IP of the VM that you want to add to the cluster that has k3s running**export AGENT_IP=54.196.113.156**#SERVER_IP is the IP of the server where k3 is installed export SERVER_IP=54.159.112.255**export USER=ec2-user**[root@ip-172-31-33-136 bin]# **./k3sup join --ip $AGENT_IP --server-ip $SERVER_IP --user ec2-user**Server IP: 54.159.112.255ssh -i /root/.ssh/id_rsa ec2-user@54.159.112.255ssh: sudo cat /var/lib/rancher/k3s/server/node-tokenK1077d707d0868b652aca7adfc21b5f34a1f0357e71b216bf8b3c94a559cd4f93a6::node:014c8ed3f6574d27db73b9c8bf67f617ssh: curl -sfL https://get.k3s.io/ | K3S_URL="https://54.159.112.255:6443" K3S_TOKEN="K1077d707d0868b652aca7adfc21b5f34a1f0357e71b216bf8b3c94a559cd4f93a6::node:014c8ed3f6574d27db73b9c8bf67f617" sh -[INFO] Finding latest release[INFO] Using v0.8.0 as release[INFO] Downloading hash [https://github.com/rancher/k3s/releases/download/v0.8.0/sha256sum-amd64.txt](https://github.com/rancher/k3s/releases/download/v0.8.0/sha256sum-amd64.txt)[INFO] Downloading binary [https://github.com/rancher/k3s/releases/download/v0.8.0/k3s](https://github.com/rancher/k3s/releases/download/v0.8.0/k3s)[INFO] Verifying binary download[INFO] Installing k3s to /usr/local/bin/k3swhich: no kubectl in (/usr/local/bin:/usr/bin)[INFO] Creating /usr/local/bin/kubectl symlink to k3swhich: no crictl in (/usr/local/bin:/usr/bin)[INFO] Creating /usr/local/bin/crictl symlink to k3swhich: no ctr in (/usr/local/bin:/usr/bin)[INFO] Creating /usr/local/bin/ctr symlink to k3s[INFO] Creating killall script /usr/local/bin/k3s-killall.sh[INFO] Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh[INFO] env: Creating environment file /etc/systemd/system/k3s-agent.service.env[INFO] systemd: Creating service file /etc/systemd/system/k3s-agent.service[INFO] systemd: Enabling k3s-agent unitCreated symlink from /etc/systemd/system/multi-user.target.wants/k3s-agent.service to /etc/systemd/system/k3s-agent.service.[INFO] systemd: Starting k3s-agentLogs: which: no kubectl in (/usr/local/bin:/usr/bin)which: no crictl in (/usr/local/bin:/usr/bin)which: no ctr in (/usr/local/bin:/usr/bin)Created symlink from /etc/systemd/system/multi-user.target.wants/k3s-agent.service to /etc/systemd/system/k3s-agent.service.Output: [INFO] Finding latest release[INFO] Using v0.8.0 as release[INFO] Downloading hash [https://github.com/rancher/k3s/releases/download/v0.8.0/sha256sum-amd64.txt](https://github.com/rancher/k3s/releases/download/v0.8.0/sha256sum-amd64.txt)[INFO] Downloading binary [https://github.com/rancher/k3s/releases/download/v0.8.0/k3s](https://github.com/rancher/k3s/releases/download/v0.8.0/k3s)[INFO] Verifying binary download[INFO] Installing k3s to /usr/local/bin/k3s[INFO] Creating /usr/local/bin/kubectl symlink to k3s[INFO] Creating /usr/local/bin/crictl symlink to k3s[INFO] Creating /usr/local/bin/ctr symlink to k3s[INFO] Creating killall script /usr/local/bin/k3s-killall.sh[INFO] Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh[INFO] env: Creating environment file /etc/systemd/system/k3s-agent.service.env[INFO] systemd: Creating service file /etc/systemd/system/k3s-agent.service[INFO] systemd: Enabling k3s-agent unit[INFO] systemd: Starting k3s-agent[root@ip-172-31-33-136 bin]# **./kubectl get nodes**NAME STATUS ROLES AGE VERSIONip-172-31-33-136.ec2.internal Ready master 19m v1.14.5-k3s.1ip-172-31-37-118.ec2.internal Ready worker 11s v1.14.5-k3s.1


推荐阅读