Skip to content

Commit

Permalink
fixing bug
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Jan 9, 2022
1 parent 640e051 commit 1138c28
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,46 @@ $ sudo kubeadm join 192.168.33.13:6443 --token xxxxxxxxxxxxxxxxxxxxxxxxxxx \
Then go back to the main node, and check your cluster again:

```bash
$ kubectl get cluster
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
main Ready control-plane,master 10m v1.23.1
worker-1 Ready <none> 3m11s v1.23.1
worker-2 Ready <none> 102s v1.23.1
```

Now create a test deployment.

```bash
$ kubectl create deployment nginx --image=nginx --port 80
$ kubectl create deployment webserver --image=nginx --port 80 --replicas=5

To access from the internet we have to expose it as follow
vagrant@master:~$ kubectl expose deployment webserver --port 80 --type=NodePort
$ kubectl expose deployment webserver --port 80 --type=NodePort
```

And then get the ip address:

```bash
$ kubectl describe services webserver
Name: webserver
Namespace: default
Labels: app=webserver
Annotations: <none>
Selector: app=webserver
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.96.1.240
IPs: 10.96.1.240
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 32502/TCP
Endpoints: 10.244.1.3:80,10.244.1.4:80,10.244.2.2:80 + 2 more...
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
```
And get it!

```bash
```
8 changes: 4 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.box = "ubuntu/focal64"
config.vm.define "main" do | w |
w.vm.hostname = "main"
w.vm.network "private_network", ip: "192.168.33.13"
Expand All @@ -17,7 +16,7 @@ Vagrant.configure("2") do |config|
SHELL
end

config.vm.box = "ubuntu/bionic64"
config.vm.box = "ubuntu/focal64"
config.vm.define "worker-1" do | w |
w.vm.hostname = "worker-1"
w.vm.network "private_network", ip: "192.168.33.14"
Expand All @@ -34,7 +33,7 @@ Vagrant.configure("2") do |config|
apt-get install -y git wget vim
SHELL
end
config.vm.box = "ubuntu/bionic64"
config.vm.box = "ubuntu/focal64"
config.vm.define "worker-2" do | w |
w.vm.hostname = "worker-2"
w.vm.network "private_network", ip: "192.168.33.15"
Expand All @@ -52,3 +51,4 @@ Vagrant.configure("2") do |config|
SHELL
end
end

21 changes: 10 additions & 11 deletions k8s-setup-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
#set -Eeuo pipefail
#trap cleanup SIGINT SIGTERM ERR EXIT


IFNAME=$1
ADDRESS="$(ip -4 addr show $IFNAME | grep "inet" | head -1 |awk '{print $2}' | cut -d/ -f1)"
sed -e "s/^.*${HOSTNAME}.*/${ADDRESS} ${HOSTNAME} ${HOSTNAME}.local/" -i /etc/hosts

# remove ubuntu-bionic entry
sed -e '/^.*ubuntu-bionic.*/d' -i /etc/hosts
# remove ubuntu-focal entry
sed -e '/^.*ubuntu-focal.*/d' -i /etc/hosts
sed -i -e 's/#DNS=/DNS=8.8.8.8/' /etc/systemd/resolved.conf

# Update /etc/hosts about other hosts
cat >> /etc/hosts <<EOF
192.168.33.13 master
192.168.33.13 main
192.168.33.14 worker-1
192.168.33.15 worker-2
EOF
Expand All @@ -25,15 +24,15 @@ apt-get install containerd -y
mkdir -p /etc/containerd
containerd config default /etc/containerd/config.toml

#install kubectl
# install kubectl
apt-get update && apt-get install -y apt-transport-https gnupg2 curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-get install bash-completion
echo 'source <(kubectl completion bash)' >>~/.bashrc
#source /usr/share/bash-completion/bash_completion
# source /usr/share/bash-completion/bash_completion
kubectl completion bash >/etc/bash_completion.d/kubectl

# Set iptables bridging
Expand All @@ -45,11 +44,11 @@ sudo echo '1' > /proc/sys/net/ipv4/ip_forward
sudo sysctl --system


#load a couple of necessary modules
# load a couple of necessary modules
sudo modprobe overlay
sudo modprobe br_netfilter
#disable swaping
#sed 's/# /swap.*/#swap.img/' /etc/fstab
#sudo swapoff -a
# disable swaping
# sed 's/# /swap.*/#swap.img/' /etc/fstab
# sudo swapoff -a

service systemd-resolved restart
service systemd-resolved restart

0 comments on commit 1138c28

Please sign in to comment.