GithubHelp home page GithubHelp logo

ericvalijani / kubernetes-go-project Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 4 KB

Simple Kubernetes Go project by the help of ChatGPT

Dockerfile 27.90% Go 72.10%
go golang kubernetes kubernetes-deployment docker

kubernetes-go-project's Introduction

kubernetes-go-project

Simple Kubernetes Go project with minikube

  1. Create a new directory for your project:
mkdir kubernetes-go-project
cd kubernetes-go-project
  1. Initialize a new Go module:
go mod init github.com/<username>/kubernetes-go-project
  1. Create a new Go file with some code. For example, create a file called main.go with the following content:
package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello, Kubernetes!")
    })

    http.ListenAndServe(":8080", nil)
}
  1. Create a Dockerfile in the same directory with the following content:
FROM golang:1.16-alpine

WORKDIR /app

COPY . .

RUN go build -o app .

CMD ["/app/app"]
  1. Create a Kubernetes deployment YAML file with the following content. This YAML file will create a deployment with one replica and a service for the deployment.

*Replace your-docker-username with your Docker Hub username.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubernetes-go-project
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kubernetes-go-project
  template:
    metadata:
      labels:
        app: kubernetes-go-project
    spec:
      containers:
      - name: kubernetes-go-project
        image: <your-docker-username>/kubernetes-go-project:latest
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: kubernetes-go-project
spec:
  selector:
    app: kubernetes-go-project
  ports:
    - name: http
      port: 80
      targetPort: 8080
  1. Build the Docker image:
docker build -t <your-docker-username>/kubernetes-go-project:latest .
  1. and push it to Docker Hub:
docker push <your-docker-username>/kubernetes-go-project:latest
  1. Start minikube and deploy the application to Kubernetes by applying the YAML file:
kubectl apply -f deployment.yaml
  1. Check the status of your service:
kubectl get services
  1. run the following command to access the application:
minikube service kubernetes-go-project

kubernetes-go-project's People

Contributors

ericvalijani avatar

Watchers

 avatar  avatar

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.