关注微信公众号
第一手干货与资讯
加入官方微信群
获取免费技术支持
Don’t have access to Cloud infrastructure? Maybe you would like to use Rancher for local Kubernetes deployments just like you do in production?
No problem, you can install Rancher 2.x on your desktop.
In this Rancher tutorial we will install Docker-for-Desktop Edge release and enable the built in Kubernetes engine to run your own personal instance of Rancher 2.x on your desktop.
For this guide you will need a couple of tools to manage and deploy to your local Kubernetes instance.
The Edge install of Docker CE for Windows/Mac includes a basic Kubernetes engine. We can leverage it to install a local Rancher Server. Download and install from the Docker Store.
Sign into Docker then right click on the Docker icon in your System Tray and select Settings
Settings
In the Advanced section increase Memory to at least 4096 MB. You may want to increase the number of CPUs assigned and the Disk image max size while you’re at it.
Advanced
Memory
4096 MB
CPUs
Disk image max size
In the Kubernetes section, check the box to enable the Kubernetes API. Docker-for-Desktop will automatically create ~/.kube/config file with credentials for kubectl to access your new local “cluster”.
Kubernetes
~/.kube/config
kubectl
Don’t see a Kubernetes section? Check the General section and make sure you are running the Edge version.
General
Open terminal and test it out. Run kubectl get nodes. kubectl should return a node named docker-for-desktop.
kubectl get nodes
docker-for-desktop
> kubectl get nodes NAME STATUS ROLES AGE VERSION docker-for-desktop Ready master 6d v1.9.6
Docker-for-Desktop doesn’t come with any extra tools installed. We could apply some static YAML manifest files with kubectl, but rather than reinventing the wheel, we want leverage existing work from the Kubernetes community. helm is the package management tool of choice for Kubernetes.
helm
helm charts provide templating syntax for Kubernetes YAML manifest documents. With helm we can create configurable deployments instead of just using static files. For more information about creating your own catalog of deployments, check out the docs at https://helm.sh/
charts
helm installs the tiller service on your cluster to manage chart deployments. Since docker-for-desktop has RBAC enabled by default we will need to use kubectl to create a serviceaccount and clusterrolebinding so tiller can deploy to our cluster for us.
tiller
chart
serviceaccount
clusterrolebinding
ServiceAccount
kube-system
kubectl -n kube-system create serviceaccount tiller
ClusterRoleBinding
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller --wait
NOTE: This tiller install has full cluster access, and may not be suitable for a production environment. Check out the helm docs for restricting tiller access to suit your security requirements.
Ingress controllers are used to provide L7 (hostname or path base) http routing from the outside world to services running in Kubernetes.
We’re going to use helm to install the Kubernetes stable community nginx-ingress chart. This will create an ingress controller on our local cluster.
nginx-ingress
helm install stable/nginx-ingress --name ingress-nginx --namespace ingress-nginx --wait
The Cert-Manger project for Kubernetes will manage the SSL certs for our local Rancher install.
Install Cert-Manager from Kubernetes Helm stable repository:
stable
helm install stable/cert-manager --name cert-manager --namespace kube-system --wait
We’re going to use Rancher’s official helm chart for the install.
The default install will use Rancher’s built in self-signed SSL certificate. For additional details and install options check out Rancher’s HA Install Docs.
rancher-server
helm repo add rancher-latest https://releases.rancher.com/server-charts/latest
rancher
Install Rancher and set a hostname for it to listen on. rancher.localhost should automatically resolve to 127.0.0.1.
rancher.localhost
127.0.0.1
helm install rancher-latest/rancher --name rancher --namespace cattle-system --set hostname=rancher.localhost --wait
hosts
If you set the hostname to something other than rancher.localhost, you may need to update your hosts file to access it.
c:\windows\system32\drivers\etc\hosts
/etc/hosts
127.0.0.1 myrancher.mydomain.com
Browse to https://rancher.localhost
Ignore the SSL warning and you should be greeted by the colorful Rancher login asking you to Set the Admin password.
Congratulations you have your very own local instance of Rancher 2.0. You can add your application charts and deploy your apps just like production. Happy Containering!
This Rancher tutorial showed you how to install your own local Rancher. To learn what Rancher can do and how it works, join a free weekly Intro to Rancher and Kubernetes online training.