Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
themeMidnight
sudo apt update
sudo apt upgrade
sudo apt-get install curl
sudo curl https://releases.rancher.com/install-docker/19.03.sh | sh
sudo usermod -aG docker <user>

Install Docker directly on EC2

Code Block
themeMidnight
ubuntu@ip-10-0-0-129:~$ sudo snap install docker
docker 19.03.11 from Canonical✓ installed


Single Node Kubernetes cluster running RKE on AWS EC2 with Helm

...

Code Block
themeMidnight
biometric:kubernetes michaelobrien$ sudo scp ~/keys/onap_rsa ubuntu@services.obrienlabs.cloud:~/
onap_rsa 100% 1675    33.6KB/s   00:00    
biometric:kubernetes michaelobrien$ ssh ubuntu@services.obrienlabs.cloud
ubuntu@ip-172-31-91-213:~$ ls
onap_rsa
ubuntu@ip-172-31-91-213:~$ sudo chmod 400 onap_rsa 
ubuntu@ip-172-31-91-213:~$ sudo cp onap_rsa ~/.ssh
# verify
ubuntu@ip-172-31-91-213:~$ cat ~/.ssh/authorized_keys 

sudo curl https://releases.rancher.com/install-docker/19.03.sh | shsudo usermod -aG docker ubuntuwget https://github.com/rancher/rke/releases/download/v1.1.9/rke_linux-amd64mv rke_linux-amd64 rkesudo mv ./rke /usr/local/bin/rkesudo chmod 777 /usr/local/bin/rkeubuntu@ip-172-31-91-213:~$ rke --version
rke version v1.1.9
ubuntu@ip-172-31-91-213:~$ rke config
[+] Cluster Level SSH Private Key Path [~/.ssh/id_rsa]: ~/.ssh/onap_rsa
[+] Number of Hosts [1]: 
[+] SSH Address of host (1) [none]: 34.200.202..
[+] SSH Port of host (1) [22]: 
[+] SSH Private Key Path of host (services.obrienlabs.cloud) [none]: ~/.ssh/onap_rsa
[+] SSH User of host (services.obrienlabs.cloud) [ubuntu]: 
[+] Is host (services.obrienlabs.cloud) a Control Plane host (y/n)? [y]: y
[+] Is host (services.obrienlabs.cloud) a Worker host (y/n)? [n]: y
[+] Is host (services.obrienlabs.cloud) an etcd host (y/n)? [n]: y
[+] Override Hostname of host (services.obrienlabs.cloud) [none]: 
[+] Internal IP of host (services.obrienlabs.cloud) [none]: 
[+] Docker socket path on host (services.obrienlabs.cloud) [/var/run/docker.sock]: 
[+] Network Plugin Type (flannel, calico, weave, canal) [canal]: 
[+] Authentication Strategy [x509]: 
[+] Authorization Mode (rbac, none) [rbac]: 
[+] Kubernetes Docker image [rancher/hyperkube:v1.18.9-rancher1]: 
[+] Cluster domain [cluster.local]: 
[+] Service Cluster IP Range [10.43.0.0/16]: 
[+] Enable PodSecurityPolicy [n]: 
[+] Cluster Network CIDR [10.42.0.0/16]: 
[+] Cluster DNS Service IP [10.43.0.10]: 
[+] Add addon manifest URLs or YAML files [no]:
ubuntu@ip-172-31-91-213:~$ vi cluster.yml 
ubuntu@ip-172-31-91-213:~$ sudo rke up
INFO[0000] Running RKE version: v1.1.9 
INFO[0000] Initiating Kubernetes cluster 
INFO[0000] [certificates] GenerateServingCertificate is disabled, checking if there are unused kubelet certificates 
INFO[0000] [certificates] Generating admin certificates and kubeconfig 
INFO[0000] Successfully Deployed state file at [./cluster.rkestate] 
INFO[0000] Building Kubernetes cluster 
INFO[0000] [dialer] Setup tunnel for host [34.200.202.57] 
INFO[0000] [network] Deploying port listener containers 
INFO[0000] Pulling image [rancher/rke-tools:v0.1.65] on host [34.200.202.57], try #1 
INFO[0004] Image [rancher/rke-tools:v0.1.65] exists on host [34.200.202.57]
ubuntu@ip-172-31-91-213:~$ sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.9/bin/linux/amd64/kubectl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 42.0M 100 42.0M 0 0 138M 0 --:--:-- --:--:-- --:--:-- 138M
ubuntu@ip-172-31-91-213:~$ sudo mv ./kubectl /usr/local/bin/kubectlubuntu@ip-172-31-91-213:~$ sudo chmod +x /usr/local/bin/kubectlubuntu@ip-172-31-91-213:~$ sudo mkdir ~/.kubeubuntu@ip-172-31-91-213:~$ sudo cp kube_config_cluster.yml ~/.kube/configubuntu@ip-172-31-91-213:~$ sudo chmod 777 ~/.kube/config
ubuntu@ip-172-31-91-213:~$ kubectl get pods --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ingress-nginx default-http-backend-598b7d7dbd-bzfwh 1/1 Running 0 10m 10.42.0.2 34.200.202.57 <none> <none>
ingress-nginx nginx-ingress-controller-qmpdv 1/1 Running 0 10m 34.200.202.57 34.200.202.57 <none> <none>
kube-system canal-szxkw 2/2 Running 0 11m 34.200.202.57 34.200.202.57 <none> <none>
kube-system coredns-849545576b-j5zn5 1/1 Running 0 11m 10.42.0.3 34.200.202.57 <none> <none>
kube-system coredns-autoscaler-5dcd676cbd-t6dsd 1/1 Running 0 11m 10.42.0.4 34.200.202.57 <none> <none>
kube-system metrics-server-697746ff48-wdr66 1/1 Running 0 11m 10.42.0.5 34.200.202.57 <none> <none>
kube-system rke-coredns-addon-deploy-job-bpdx6 0/1 Completed 0 11m 34.200.202.57 34.200.202.57 <none> <none>
kube-system rke-ingress-controller-deploy-job-6b7s5 0/1 Completed 0 10m 34.200.202.57 34.200.202.57 <none> <none>
kube-system rke-metrics-addon-deploy-job-44jd2 0/1 Completed 0 11m 34.200.202.57 34.200.202.57 <none> <none>
kube-system rke-network-plugin-deploy-job-6m7sc 0/1 Completed 0 11m 34.200.202.57 34.200.202.57 <none> <none>
ubuntu@ip-172-31-91-213:~$ kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% 
34.200.202.57 145m 7% 1925Mi 24% 
ubuntu@ip-172-31-91-213:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
34.200.202.57 Ready controlplane,etcd,worker 11m v1.18.9


Add Grafana dashboard


vi grafana-datasource-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-datasources
  namespace: monitoring
data:
  prometheus.yaml: |-
    {
        "apiVersion": 1,
        "datasources": [
            {
               "access":"proxy",
                "editable": true,
                "name": "prometheus",
                "orgId": 1,
                "type": "prometheus",
                "url": "http://prometheus-service.monitoring.svc:8080",
                "version": 1
            }
        ]
    }



vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      name: grafana
      labels:
        app: grafana
    spec:
      containers:
      - name: grafana
        image: grafana/grafana:latest
        ports:
        - name: grafana
          containerPort: 3000
        resources:
          limits:
            memory: "2Gi"
            cpu: "1000m"
          requests: 
            memory: "1Gi"
            cpu: "500m"
        volumeMounts:
          - mountPath: /var/lib/grafana
            name: grafana-storage
          - mountPath: /etc/grafana/provisioning/datasources
            name: grafana-datasources
            readOnly: false
      volumes:
        - name: grafana-storage
          emptyDir: {}
        - name: grafana-datasources
          configMap:
              defaultMode: 420
              name: grafana-datasources



vi service.yaml
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: monitoring
  annotations:
      prometheus.io/scrape: 'true'
      prometheus.io/port:   '3000'
spec:
  selector: 
    app: grafana
  type: NodePort  
  ports:
    - port: 3000
      targetPort: 3000
      nodePort: 32000


Code Block
themeMidnight
ubuntu@ip-172-31-91-213:~$ kubectl create namespace monitoring
namespace/monitoring created
ubuntu@ip-172-31-91-213:~$ kubectl create -f grafana-datasource-config.yaml
configmap/grafana-datasources created
ubuntu@ip-172-31-91-213:~/grafana$ kubectl create -f deployment.yaml
deployment.apps/grafana created
ubuntu@ip-172-31-91-213:~/grafana$ kubectl create -f service.yaml
service/grafana created

ubuntu@ip-172-31-91-213:~/grafana$ kubectl get pods --all-namespaces
monitoring      grafana-86b84774bb-xct98                  1/1     Running     0          2m21s
ubuntu@ip-172-31-91-213:~/grafana$ kubectl get services --all-namespaces
monitoring      grafana                NodePort    10.43.36.85    <none>        3000:32000/TCP           52s

...