Skip to content

Commit c3125b6

Browse files
Merge pull request #1 from ajaychinthapalli/develop
setup-kubernetes
2 parents 666f40b + 2a886e7 commit c3125b6

9 files changed

+303
-2
lines changed

Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Just for learning purposes obviously
2+
FROM httpd:2.4-alpine
3+
4+
COPY ./index.html /usr/local/apache2/htdocs/

README.md

+255-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,255 @@
1-
# setup-kubernetes
2-
Local kubernetes setup on macOS with minikube on VirtualBox and local Docker registry
1+
# About My Mac (macOS High Sierra 10.13.6)
2+
```text
3+
Model Name : MacBook Pro
4+
Model Identifier : MacBookPro14,2
5+
Processor Name : Intel Core i5
6+
Processor Speed : 3.1 GHz
7+
Number of Processors : 1
8+
Total Number of Cores: 2
9+
L2 Cache (per Core) : 256 KB
10+
L3 Cache : 4 MB
11+
Memory : 8 GB
12+
```
13+
# Requirements
14+
Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:
15+
```text
16+
sysctl -a | grep machdep.cpu.features | grep VMX
17+
```
18+
If there's output, you're good!
19+
```text
20+
bash-5.2$ sysctl -a | grep machdep.cpu.features | grep VMX
21+
machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C
22+
```
23+
24+
# Prerequisites
25+
- kubectl
26+
- docker
27+
- minikube
28+
- virtualbox
29+
```text
30+
brew update
31+
brew install kubectl
32+
brew install --cask docker virtualbox
33+
brew install minikube
34+
```
35+
36+
# Verification
37+
```text
38+
bash-5.2$ docker --version
39+
Docker version 19.03.13, build 4484c46d9d
40+
bash-5.2$ docker-compose --version
41+
docker-compose version 1.27.4, build 40524192
42+
bash-5.2$ minikube version
43+
minikube version: v1.27.1
44+
commit: fe869b5d4da11ba318eb84a3ac00f336411de7ba
45+
bash-5.2$ kubectl version --client
46+
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
47+
Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.3", GitCommit:"434bfd82814af038ad94d62ebe59b133fcb50506", GitTreeState:"clean", BuildDate:"2022-10-12T10:47:25Z", GoVersion:"go1.19.2", Compiler:"gc", Platform:"darwin/amd64"}
48+
Kustomize Version: v4.5.7
49+
```
50+
51+
# Start
52+
```text
53+
minikube start
54+
```
55+
It will take a while, expected output:
56+
```text
57+
bash-5.2$ minikube start
58+
😄 minikube v1.27.1 on Darwin 10.13.6
59+
🎉 minikube 1.28.0 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.28.0
60+
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
61+
62+
✨ Automatically selected the docker driver. Other choices: hyperkit, ssh
63+
💨 For improved Docker Desktop performance, Upgrade Docker Desktop to a newer version (Minimum recommended version is 20.10.0, minimum supported version is 18.09.0, current version is 19.03.13)
64+
📌 Using Docker Desktop driver with root privileges
65+
👍 Starting control plane node minikube in cluster minikube
66+
🚜 Pulling base image ...
67+
💾 Downloading Kubernetes v1.25.2 preload ...
68+
> preloaded-images-k8s-v18-v1...: 385.41 MiB / 385.41 MiB 100.00% 15.09 M
69+
> gcr.io/k8s-minikube/kicbase: 387.11 MiB / 387.11 MiB 100.00% 8.39 MiB p
70+
> gcr.io/k8s-minikube/kicbase: 0 B [________________________] ?% ? p/s 53s
71+
🔥 Creating docker container (CPUs=2, Memory=1987MB) ...
72+
🐳 Preparing Kubernetes v1.25.2 on Docker 20.10.18 ...
73+
▪ Generating certificates and keys ...
74+
▪ Booting up control plane ...
75+
▪ Configuring RBAC rules ...
76+
🔎 Verifying Kubernetes components...
77+
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
78+
🌟 Enabled addons: storage-provisioner, default-storageclass
79+
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
80+
```
81+
Great! You now have a running Kubernetes cluster locally. Minikube started a virtual machine for you, and a Kubernetes cluster is now running in that VM.
82+
83+
# Check k8s
84+
```text
85+
bash-5.2$ kubectl get nodes
86+
NAME STATUS ROLES AGE VERSION
87+
minikube Ready control-plane 3m19s v1.25.2
88+
```
89+
90+
# Use minikube's built-in docker daemon:
91+
```text
92+
eval $(minikube docker-env)
93+
```
94+
Add this line to `.bash_profile` or `.zshrc` or ... if you want to use minikube's daemon by default (or if you do not want to set this every time you open a new terminal).
95+
96+
You can revert back to the host docker daemon by running:
97+
```text
98+
eval $(docker-machine env -u)
99+
```
100+
If you now run `docker ps`, it should now output something like:
101+
```text
102+
bash-5.2$ docker ps
103+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
104+
c7b879609c60 6e38f40d628d "/storage-provisioner" 7 minutes ago Up 7 minutes k8s_storage-provisioner_storage-provisioner_kube-system_c410ca2c-cecf-410d-bb13-38e969048f92_0
105+
cfa5f44183de 5185b96f0bec "/coredns -conf /etc…" 7 minutes ago Up 7 minutes k8s_coredns_coredns-565d847f94-zr6pd_kube-system_f28ff7fa-8899-4860-bdb5-6229fa339304_0
106+
60ba3882a370 k8s.gcr.io/pause:3.6 "/pause" 7 minutes ago Up 7 minutes k8s_POD_storage-provisioner_kube-system_c410ca2c-cecf-410d-bb13-38e969048f92_0
107+
328aad89849c 1c7d8c51823b "/usr/local/bin/kube…" 7 minutes ago Up 7 minutes k8s_kube-proxy_kube-proxy-tzmgb_kube-system_601e548d-87fe-4dfb-b7ca-126ba8e267e2_0
108+
c5b1f26169e2 k8s.gcr.io/pause:3.6 "/pause" 7 minutes ago Up 7 minutes k8s_POD_coredns-565d847f94-zr6pd_kube-system_f28ff7fa-8899-4860-bdb5-6229fa339304_0
109+
df9e76992434 k8s.gcr.io/pause:3.6 "/pause" 7 minutes ago Up 7 minutes k8s_POD_kube-proxy-tzmgb_kube-system_601e548d-87fe-4dfb-b7ca-126ba8e267e2_0
110+
afb8d718de0e dbfceb93c69b "kube-controller-man…" 8 minutes ago Up 8 minutes k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_2e75927e0fd852156c6691ad3046836e_1
111+
d38816460fb5 97801f839490 "kube-apiserver --ad…" 8 minutes ago Up 8 minutes k8s_kube-apiserver_kube-apiserver-minikube_kube-system_0043f0e06f8033573472a91b2322f830_0
112+
5730cd42e0d7 ca0ea1ee3cfd "kube-scheduler --au…" 8 minutes ago Up 8 minutes k8s_kube-scheduler_kube-scheduler-minikube_kube-system_d9e39786b2e03d044abb6c68064d5241_0
113+
c9d592d3afb3 a8a176a5d5d6 "etcd --advertise-cl…" 8 minutes ago Up 8 minutes k8s_etcd_etcd-minikube_kube-system_bd495b7643dfc9d3194bd002e968bc3d_0
114+
36a4c8d23d9a k8s.gcr.io/pause:3.6 "/pause" 8 minutes ago Up 8 minutes k8s_POD_kube-controller-manager-minikube_kube-system_2e75927e0fd852156c6691ad3046836e_0
115+
0dec781dbb16 k8s.gcr.io/pause:3.6 "/pause" 8 minutes ago Up 8 minutes k8s_POD_etcd-minikube_kube-system_bd495b7643dfc9d3194bd002e968bc3d_0
116+
f6a4e6053b1d k8s.gcr.io/pause:3.6 "/pause" 8 minutes ago Up 8 minutes k8s_POD_kube-scheduler-minikube_kube-system_d9e39786b2e03d044abb6c68064d5241_0
117+
305e62608a38 k8s.gcr.io/pause:3.6 "/pause" 8 minutes ago Up 8 minutes k8s_POD_kube-apiserver-minikube_kube-system_0043f0e06f8033573472a91b2322f830_0
118+
```
119+
120+
# Build, deploy and run an image on your local k8s setup
121+
First setup a local registry, so Kubernetes can pull the images from there
122+
```text
123+
docker run -d -p 5000:5000 --restart=always --name registry registry:2
124+
```
125+
```text
126+
bash-5.2$ docker run -d -p 5000:5000 --restart=always --name registry registry:2
127+
Unable to find image 'registry:2' locally
128+
2: Pulling from library/registry
129+
ca7dd9ec2225: Pull complete
130+
c41ae7ad2b39: Pull complete
131+
1ed0fc8a6161: Pull complete
132+
21df229223d2: Pull complete
133+
626897ccab21: Pull complete
134+
Digest: sha256:ce14a6258f37702ff3cd92232a6f5b81ace542d9f1631966999e9f7c1ee6ddba
135+
Status: Downloaded newer image for registry:2
136+
7efa3289fa506fb581ceb4fb252f346c8bdeec2a1875d7ce5398af7a405ba06b
137+
```
138+
## Build
139+
- Build the Dockerfile below locally
140+
```text
141+
bash-5.2$ docker build . --tag my-app
142+
Sending build context to Docker daemon 102.4kB
143+
Step 1/2 : FROM httpd:2.4-alpine
144+
2.4-alpine: Pulling from library/httpd
145+
c158987b0551: Pull complete
146+
af0dc97e3e7a: Pull complete
147+
7a4f45a5d61d: Pull complete
148+
3b6adf47f20b: Pull complete
149+
a7c0837131ea: Pull complete
150+
82cf25aabba6: Pull complete
151+
Digest: sha256:86ed18b4670b3be349e62f05c34bf0c28f3e0a73732969c417fd53e04af807f4
152+
Status: Downloaded newer image for httpd:2.4-alpine
153+
---> 4e7c9ee81ce6
154+
Step 2/2 : COPY ./index.html /usr/local/apache2/htdocs/
155+
---> ff1c26ada38c
156+
Successfully built ff1c26ada38c
157+
Successfully tagged my-app:latest
158+
```
159+
- You should now have an image named 'my-app' locally, check by using docker images (or your own image of course). You can then publish it to your local docker registry
160+
```text
161+
docker tag my-app localhost:5000/my-app:0.1.0
162+
```
163+
- Running `docker images` should now output the following:
164+
```text
165+
bash-5.2$ docker images
166+
REPOSITORY TAG IMAGE ID CREATED SIZE
167+
localhost:5000/my-app 0.1.0 ff1c26ada38c 3 minutes ago 56.9MB
168+
my-app latest ff1c26ada38c 3 minutes ago 56.9MB
169+
httpd 2.4-alpine 4e7c9ee81ce6 11 days ago 56.9MB
170+
registry 2 81c944c2288b 4 weeks ago 24.1MB
171+
registry.k8s.io/kube-apiserver v1.25.2 97801f839490 2 months ago 128MB
172+
registry.k8s.io/kube-scheduler v1.25.2 ca0ea1ee3cfd 2 months ago 50.6MB
173+
registry.k8s.io/kube-controller-manager v1.25.2 dbfceb93c69b 2 months ago 117MB
174+
registry.k8s.io/kube-proxy v1.25.2 1c7d8c51823b 2 months ago 61.7MB
175+
registry.k8s.io/pause 3.8 4873874c08ef 5 months ago 711kB
176+
registry.k8s.io/etcd 3.5.4-0 a8a176a5d5d6 6 months ago 300MB
177+
registry.k8s.io/coredns/coredns v1.9.3 5185b96f0bec 6 months ago 48.8MB
178+
k8s.gcr.io/pause 3.6 6270bb605e12 15 months ago 683kB
179+
gcr.io/k8s-minikube/storage-provisioner v5 6e38f40d628d 20 months ago 31.5MB
180+
```
181+
182+
## Deploy & Run
183+
- Creates Kubernetes objects:
184+
```text
185+
bash-5.2$ kubectl create -f my-app.yml
186+
deployment.apps/my-app created
187+
service/my-app created
188+
```
189+
- You should now see your pod and your service:
190+
```text
191+
bash-5.2$ kubectl get all
192+
NAME READY STATUS RESTARTS AGE
193+
pod/my-app-674df799d7-fsdn8 1/1 Running 0 4m4s
194+
195+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
196+
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 49m
197+
service/my-app NodePort 10.108.149.3 <none> 80:31385/TCP 4m5s
198+
199+
NAME READY UP-TO-DATE AVAILABLE AGE
200+
deployment.apps/my-app 1/1 1 1 4m5s
201+
202+
NAME DESIRED CURRENT READY AGE
203+
replicaset.apps/my-app-674df799d7 1 1 1 4m6s
204+
```
205+
- The configuration exposes my-app outside of the cluster, you can get the address to access it by running:
206+
```text
207+
bash-5.2$ minikube service my-app --url
208+
http://127.0.0.1:61249
209+
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
210+
```
211+
This should give an output like `http://127.0.0.1:61249` (the port will most likely differ). you should see "Hello World!". You just accessed your application from outside of your local Kubernetes cluster!
212+
![hello-world.png](images%2Fhello-world.png)
213+
214+
# Kubernetes GUI
215+
```text
216+
🔌 Enabling dashboard ...
217+
▪ Using image docker.io/kubernetesui/dashboard:v2.7.0
218+
▪ Using image docker.io/kubernetesui/metrics-scraper:v1.0.8
219+
🤔 Verifying dashboard health ...
220+
🚀 Launching proxy ...
221+
🤔 Verifying proxy health ...
222+
🎉 Opening http://127.0.0.1:61358/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
223+
```
224+
![kubernetes-dashboard.png](images%2Fkubernetes-dashboard.png)
225+
![kubernetes-deployments.png](images%2Fkubernetes-deployments.png)
226+
![kubernetes-replicasets.png](images%2Fkubernetes-replicasets.png)
227+
![kubernetes-services.png](images%2Fkubernetes-services.png)
228+
229+
# Delete deployment of my-app
230+
```text
231+
bash-5.2$ kubectl delete deploy my-app
232+
deployment.apps "my-app" deleted
233+
```
234+
```text
235+
bash-5.2$ kubectl delete service my-app
236+
service "my-app" deleted
237+
```
238+
You're now good to go and deploy other images!
239+
240+
# Reset
241+
```text
242+
bash-5.2$ minikube stop;
243+
✋ Stopping node "minikube" ...
244+
🛑 Powering off "minikube" via SSH ...
245+
🛑 1 node stopped.
246+
bash-5.2$ minikube delete;
247+
🔥 Deleting "minikube" in docker ...
248+
🔥 Deleting container "minikube" ...
249+
🔥 Removing /Users/ajay/.minikube/machines/minikube ...
250+
💀 Removed all traces of the "minikube" cluster.
251+
bash-5.2$ rm -rf ~/.minikube ~/.kube;
252+
```
253+
254+
# Version
255+
Last tested on 2022 December 12th (**macOS High Sierra 10.13.6**)

images/hello-world.png

29.4 KB
Loading

images/kubernetes-dashboard.png

288 KB
Loading

images/kubernetes-deployments.png

215 KB
Loading

images/kubernetes-replicasets.png

230 KB
Loading

images/kubernetes-services.png

274 KB
Loading

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World!

my-app.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# APP DEPLOYMENT
2+
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
labels:
7+
run: my-app
8+
name: my-app
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
run: my-app-exposed
14+
template:
15+
metadata:
16+
labels:
17+
run: my-app-exposed
18+
spec:
19+
containers:
20+
- image: localhost:5000/my-app:0.1.0
21+
name: my-app
22+
ports:
23+
- containerPort: 80
24+
protocol: TCP
25+
26+
---
27+
28+
# APP SERVICE
29+
30+
apiVersion: v1
31+
kind: Service
32+
metadata:
33+
labels:
34+
run: my-app
35+
name: my-app
36+
spec:
37+
ports:
38+
- port: 80
39+
protocol: TCP
40+
targetPort: 80
41+
selector:
42+
run: my-app-exposed
43+
type: NodePort

0 commit comments

Comments
 (0)