Giter Club home page Giter Club logo

kubernetes-101's Introduction

kubernetes-101

Tutorial to build and deploy a simple Python app in Kubernetes. The walkthrough is available here.

Make sure that you have access to a Kubernetes cluster.

Build a Docker image from existing Python source code and push it to Docker Hub. Replace DOCKER_HUB_USER with your Docker Hub username.

cd Docker
docker build -t <DOCKER_HUB_USER>/web .
docker push <DOCKER_HUB_USER>/web

Launch the app with Docker Compose

docker-compose up -d 

Test the app

curl localhost:5000

Deploy the app to Kubernetes

cd ../Kubernetes
kubectl create -f db-pod.yml
kubectl create -f db-svc.yml
kubectl create -f web-pod.yml
kubectl create -f web-svc.yml
kubectl create -f web-rc.yml

Check that the Pods and Services are created

kubectl get pods
kubectl get svc

Get the NodePort for the web Service. Make a note of the port.

kubectl describe svc web

Test the app by accessing the NodePort of one of the nodes.

kubectl get nodes
curl <NODE_IP>:<NODEPORT>

kubernetes-101's People

Contributors

janakiramm avatar tahir24434 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kubernetes-101's Issues

Failed to connect - connection refused

Steps to reproduce

  1. Pulled this git repo
  2. Did docker-compose up -d of Docker/docker-compose.yaml

โžœ Docker git:(master) docker-compose ps
Name Command State Ports

docker_web_1 python app.py Up 0.0.0.0:3000->5000/tcp
redis docker-entrypoint.sh redis ... Up 6379/tcp

โžœ Docker git:(master) curl localhost:3000
curl: (7) Failed to connect to localhost port 3000: Connection refused

Status ImagePullBackOff in kubectl get pods

Hi all, I am trying to start minikube with the examples, but when I check pods status

bryanleekw@nb1:~/Projects/kubernetes-101/Kubernetes$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-web-5f796bf89-c495j 0/1 ImagePullBackOff 0 1d
redis 1/1 Running 0 15m
web 1/1 Running 0 15m
web-hr4jv 1/1 Running 0 15m

================================================
I check the pods status by describe, and unable to pull that images
bryanleekw@nb1:~/Projects/kubernetes-101/Kubernetes$ kubectl describe pods my-web-5f796bf89-c495j
Name: my-web-5f796bf89-c495j
Namespace: default
Node: minikube/192.168.99.100
Start Time: Wed, 03 Jan 2018 22:52:14 +0800
Labels: pod-template-hash=193526945
run=my-web
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"my-web-5f796bf89","uid":"afb6f69c-f095-11e7-9de0-080027302ed5","...
Status: Running
IP: 172.17.0.2
Controlled By: ReplicaSet/my-web-5f796bf89
Containers:
my-web:
Container ID: docker://4a69f9aea721506c3f1fe60f1b7e7d171217182cf60f2955fdc7a41f81a1d90f
Image: 192.168.99.100:80/myweb
Image ID: docker-pullable://192.168.99.100:80/myweb@sha256:8e79b39e50dba9fc733260bede99f43655faab6ddfd6e0123b78f31757c9ded7
Port: 80/TCP
State: Waiting
Reason: ImagePullBackOff
Last State: Terminated
Reason: Error
Exit Code: 255
Started: Wed, 03 Jan 2018 22:52:15 +0800
Finished: Fri, 05 Jan 2018 08:30:53 +0800
Ready: False
Restart Count: 0
Environment:
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-4f4ds (ro)
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-4f4ds:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-4f4ds
Optional: false
QoS Class: BestEffort
Node-Selectors:
Tolerations:
Events:
Type Reason Age From Message


Normal Scheduled 1d default-scheduler Successfully assigned my-web-5f796bf89-c495j to minikube
Normal SuccessfulMountVolume 1d kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-4f4ds"
Normal Pulling 1d kubelet, minikube pulling image "192.168.99.100:80/myweb"
Normal Pulled 1d kubelet, minikube Successfully pulled image "192.168.99.100:80/myweb"
Normal Created 1d kubelet, minikube Created container
Normal Started 1d kubelet, minikube Started container
Normal SandboxChanged 17m kubelet, minikube Pod sandbox changed, it will be killed and re-created.
Normal SuccessfulMountVolume 17m kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-4f4ds"
Normal Pulling 16m (x3 over 17m) kubelet, minikube pulling image "192.168.99.100:80/myweb"
Warning Failed 16m (x3 over 17m) kubelet, minikube Failed to pull image "192.168.99.100:80/myweb": rpc error: code = Unknown desc = Error response from daemon: Get http://192.168.99.100:80/v2/: dial tcp 192.168.99.100:80: getsockopt: connection refused
Warning BackOff 15m (x5 over 16m) kubelet, minikube Back-off restarting failed container
Normal BackOff 7m (x25 over 17m) kubelet, minikube Back-off pulling image "192.168.99.100:80/myweb"
Warning FailedSync 2m (x71 over 17m) kubelet, minikube Error syncing pod
bryanleekw@nb1:~/Projects/kubernetes-101/Kubernetes$

=================================================================
However, when I issued docker images command, that image exists there.

bryanleekw@nb1:~/Projects/kubernetes-101/Kubernetes$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
bryanmunich/webnew latest 72a89934aba4 15 hours ago 95.8MB
192.168.99.100:80/myweb latest 3f55de602b18 36 hours ago 177MB
redis latest 1e70071f4af4 3 weeks ago 107MB
gcr.io/google_containers/kubernetes-dashboard-amd64 v1.8.0 55dbc28356f2 5 weeks ago 119MB
gcr.io/k8s-minikube/storage-provisioner v1.8.0 4689081edb10 8 weeks ago 80.8MB
gcr.io/k8s-minikube/storage-provisioner v1.8.1 4689081edb10 8 weeks ago 80.8MB
gcr.io/google_containers/k8s-dns-sidecar-amd64 1.14.5 fed89e8b4248 3 months ago 41.8MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64 1.14.5 512cd7425a73 3 months ago 49.4MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 1.14.5 459944ce8cc4 3 months ago 41.4MB
gcr.io/google_containers/kubernetes-dashboard-amd64 v1.6.3 691a82db1ecd 5 months ago 139MB
gcr.io/google-containers/kube-addon-manager v6.4-beta.2 0a951668696f 6 months ago 79.2MB
gcr.io/google_containers/pause-amd64 3.0 99e59f495ffa 20 months ago 747kB

Failed to connect to localhost port 5000: Connection refused

The images was created, when I have submitted docker-compose with image built.
However, when I try to curl localhost:5000, and it shows following error
curl: (7) Failed to connect to localhost port 5000: Connection refused

I tried to find out why with using iptables -t nat -L -n, it should be correct to open the port. Do you guys have any ideas about why? thanks

Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DOCKER all -- 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
DOCKER all -- 0.0.0.0/0 !127.0.0.0/8 ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 172.17.0.0/16 0.0.0.0/0
MASQUERADE all -- 172.18.0.0/16 0.0.0.0/0
MASQUERADE tcp -- 172.17.0.3 172.17.0.3 tcp dpt:5000

Chain DOCKER (2 references)
target prot opt source destination
RETURN all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3000 to:172.17.0.3:5000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.