Skip to content

Instantly share code, notes, and snippets.

@salah93
Created May 9, 2020 19:51
Show Gist options
  • Save salah93/47d436b32814fe65f747b46ad74cac5d to your computer and use it in GitHub Desktop.
Save salah93/47d436b32814fe65f747b46ad74cac5d to your computer and use it in GitHub Desktop.
kubernetes with minikube

Kubernetes

Installations

I am operating on a Fedora 31 OS with docker installed, I can run minikube on my machine directly (rather than in a vm) with docker by specifying minikube with --driver=docker.

I think this will be fine for development/exploration.

kubectl

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 version --client

minikube

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube
sudo mv minikube /usr/local/bin
minikube start --driver=docker
    πŸ˜„  minikube v1.9.2 on Fedora 31
    ✨  Using the docker driver based on user configuration
    πŸ‘  Starting control plane node m01 in cluster minikube
    🚜  Pulling base image ...
    πŸ’Ύ  Downloading Kubernetes v1.18.0 preload ...
        > preloaded-images-k8s-v2-v1.18.0-docker-overlay2-amd64.tar.lz4: 542.91 MiB
    πŸ”₯  Creating Kubernetes in docker container with (CPUs=2) (8 available), Memory=3900MB (15769MB available) ...
    🐳  Preparing Kubernetes v1.18.0 on Docker 19.03.2 ...
        β–ͺ kubeadm.pod-network-cidr=10.244.0.0/16
    🌟  Enabling addons: default-storageclass, storage-provisioner
    πŸ„  Done! kubectl is now configured to use "minikube"
minikube status
    m01
    host: Running
    kubelet: Running
    apiserver: Running
    kubeconfig: Configured
kubectl cluster-info
    Kubernetes master is running at https://172.17.0.2:8443
    KubeDNS is running at https://172.17.0.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To stop

minikube stop

To clean up local state

minikube delete

Deploying simple app

Create Namespace

minikube start --driver=docker
kubectl create namespace flask
kubectl get namespace

Create Pod

cat flask-pod.yaml
cat <<EOF > flask-pod.yaml
apiVersion: v1
kind: Pod
metadata:
    name: flask-pod
    labels:
        app: flask-helloworld
spec:
    containers:
    - name: flask
        image: digitalocean/flask-helloworld:latest
        ports:
        - containerPort: 5000
EOF
kubectl apply -f flask-pod.yaml -n flask
kubectl get pod -n flask
kubectl describe pod -n flask
kubectl port-forward pods/flask-pod -n flask 5000:5000

When we are ready to move on

kubectl delete pod flask-pod -n flask

Create Deployment

cat <<EOF > flask-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
    name: flask-dep
    labels:
        app: flask-helloworld
spec:
    replicas: 2
    selector:
        matchLabels:
            app: flask-helloworld
    template:
        metadata:
            labels:
                app: flask-helloworld
        spec:
            containers:
            - name: flask
                image: digitalocean/flask-helloworld:latest
                ports:
                - containerPort: 5000
EOF
kubectl apply -f flask-deployment.yaml -n flask
kubectl get deploy -n flask
kubectl get pod -n flask
kubectl port-forward deployment/flask-dep -n flask 5000:5000
kubectl rollout status deployment/flask-dep -n flask
kubectl get replicaset -n flask
kubectl rollout restart deployment/flask-dep -n flask
kubectl scale --current-replicas=2 --replicas=3 deployment/flask-dep -n flask
kubectl get replicaset -n flask
kubectl get deploy -n flask
kubectl get pods -n flask

Create Service

cat <<EOF > flask-service.yaml
apiVersion: v1
kind: Service
metadata:
    name: flask-svc
    labels:
        app: flask-helloworld
spec:
    type: LoadBalancer
    ports:
    - port: 80
      targetPort: 5000
      protocol: TCP
    selector:
        app: flask-helloworld
EOF
kubectl apply -f flask-service.yaml -n flask
kubectl get svc -n flask
minikube service flask-svc -n flask

Cleanup

kubectl delete svc flask-svc -n flask
kubectl delete deploy flask-dep -n flask
kubectl delete namespace flask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment