Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Kubernetes



Setup Cluster

https://ramhiser.com/post/2018-05-20-setting-up-a-kubernetes-cluster-on-aws-in-5-minutes/
https://www.youtube.com/watch?v=RZwb6hhZvqM

curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py --user
pip --version
echo $PATH
export PATH=~/.local/bin:$PATH
echo $PATH
source ~/.bash_profile
pip --version
pip install awscli --upgrade --user
aws --version
pip install awscli --upgrade --user
aws configure

curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
chmod +x kops-linux-amd64
sudo mv kops-linux-amd64 /usr/local/bin/kops

aws s3api create-bucket --bucket hasaranga-kops-state-store --region us-west-2 (error)

aws s3api create-bucket --bucket hasaranga-kops-state-store --region us-east-1
aws s3api put-bucket-versioning --bucket hasaranga-kops-state-store  --versioning-configuration Status=Enabled
export KOPS_CLUSTER_NAME=hasaranga.k8s.local
export KOPS_STATE_STORE=s3://hasaranga-kops-state-store

export PATH=/usr/local/bin:$PATH
kops
kops create cluster --node-count=2 --node-size=t2.medium --zones=us-east-1a
//kops edit cluster
//kops create secret --name hasaranga.k8s.local sshpublickey admin -i ~/.ssh/id_rsa.pub
//ssh-keygen
//kops create secret --name hasaranga.k8s.local sshpublickey admin -i ~/.ssh/id_rsa.pub
kops validate cluster
kops update cluster --name ${KOPS_CLUSTER_NAME} --yes
kops validate cluster
few minutes
kops validate cluster
kops validate cluster
kops validate cluster
kops validate cluster

---------------

To check cluster:
kops get cluster --state s3://hasaranga-kops-state-store
kops get cluster --state s3://hasaranga-kops-state-store -o yaml (full)

To delete your cluster:
kops delete cluster --name hasaranga.k8s.local --yes
or
kops delete cluster --state=s3://hasaranga-kops-state-store --name hasaranga.k8s.local --yes (not tested)

To edit node count
kops edit instancegroup nodes --state s3://hasaranga-kops-state-store --> edit min & max
kops update cluster --state s3://hasaranga-kops-state-store ( = kops update cluster [cluster_name_here) ====>> shows diff
====To Apply===
kops update cluster --state s3://hasaranga-kops-state-store --yes


Deploy
https://codefresh.io/kubernetes-tutorial/tutorial-deploying-kubernetes-to-aws-using-kops/


curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kops create cluster --node-count=2 --node-size=t2.medium --zones=us-east-1a
kops update cluster --name ${KOPS_CLUSTER_NAME} --yes
kops validate cluster
kubectl get nodes

----------
   64  docker pull nginx:1.10.2-alpine
   65  yum install docker
   66  yum install epel-release -y
   67  yum install docker-io
   68     systemctl start docker
   69     systemctl status docker
   70     systemctl enable docker
   71     docker run hello-world
   72  yum install docker-io
   73  systemctl status docker
   74  docker pull nginx:1.10.2-alpine
   75  docker images
   76  kubectl run nginx --image=docker.io/nginx:1.10.2-alpine --replicas=2 --port=80
   77  kubectl get deployments
   78  kubectl get pods
   79  kubectl expose deployment nginx --port=80 --type=LoadBalancer
   80  kubectl get services --> see load balancer on aws
https://www.youtube.com/watch?v=DFOmjp-Ee4c


This is also good: https://jee-appy.blogspot.com/2017/10/setup-kubernetes-cluster-kops-aws.html
https://www.youtube.com/watch?v=IImQrJWbaDo

Advanced one: https://www.youtube.com/watch?v=PuNtfPWTp2g

kops create cluster
--yes
--networking=weave
--zones=us-east-1a,us-east-1b ====> 3 masters
--topology=private ===> all ec2's are private
--bastion ===> to access ec2's, creating only this on public
demo.hasarangaprasad.tk  ==> cluster name

--vpc=if_need_existing_one_to_use_then_mention_here
--network-cidr=if_need_existing_one_to_use_then_mention_here


Creating Dashboard
kubectl create -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes-dashboard/v1.8.3.yaml
or
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
kubectl proxy
kubectl config view --minify
kubectl proxy
kubectl apply -f https://gist.githubusercontent.com/chukaofili/9e94d966e73566eba5abdca7ccb067e6/raw/0f17cd37d2932fb4c3a2e7f4434d08bc64432090/k8s-dashboard-admin-user.yaml
kubectl get sa admin-user -n kube-system
kubectl get sa admin-user -n kube-system
kubectl describe sa admin-user -n kube-system
kubectl describe secret admin-user-token-d4wnf -n kube-system

Browser--> https://<Master node connected ELB dns>/ui/ paste above token



==========================================================
kubeadm 

in virtualbox, install centos minimal , keep dhcp in the networking
tools -> preference -> network -> create "nat network" -> add port fowerding to connect guest vms from host machine (host port=2222, guest port 22, guest ip=<auto assgned ip for ech vm>)
each vm -> go to settings -> network -> select nat network

to connect via host ssh root@127.0.0.1 -p 2222

summary
hostnamectl set-hostname master; systemctl restart network; sed -i "1s/$/ $(hostname | tr '\n' ' ')/" /etc/hosts;

systemctl disable firewalld; systemctl stop firewalld;
curl -sSL https://get.docker.com/ | sh
systemctl start docker.service
systemctl enable docker.service

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

systemctl enable --now kubelet
swapoff -a
sysctl net.bridge.bridge-nf-call-iptables=1 (if errors -> modprobe br_netfilter )
[master] kubeadm init --apiserver-advertise-address=10.0.2.5 --pod-network-cidr=10.10.0.0/16
[master] mkdir -p $HOME/.kube
 [master] sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 [master] sudo chown $(id -u):$(id -g) $HOME/.kube/config

[master]kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/62e44c867a2846fefb68bd5f178daf4da3095ccb/Documentation/kube-flannel.yml
[node] join
kubectl get nodes

kubectl get nodes
kubectl get pods --all-namespaces


[[[[[[[[[[[to reset, keubadm rest  ]]]]]]]]]

reference:
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#pod-network

No comments:

Post a Comment