Post

Kubernetes Essentials - Starting Your Journey with K8S - Lesson 01

Dive into the world of Kubernetes with our comprehensive guide, ‘Kubernetes Essentials: Starting Your Journey with K8S - Lesson 01’. This introductory lesson is tailored for beginners and offers a detailed overview of Kubernetes’ basic concepts, architecture, and its role in modern cloud computing. Discover how Kubernetes revolutionizes container orchestration, simplifying deployment, scaling, and management of containerized applications. This article is the perfect starting point for anyone looking to build a strong foundation in Kubernetes.

Build Helloworld.go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
    "fmt"
    "log"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    log.Println("received request from", r.RemoteAddr, r.URL.Path[1:])
    var welcome = r.URL.Path[1:]
    if len(welcome) == 0 {
        welcome = "World"
    }
    fmt.Fprintf(w, "Hello, %s! ", welcome)
}

func main() {
    http.HandleFunc("/", handler)
    log.Println("starting server on port 9000")
    log.Fatal(http.ListenAndServe(":9000", nil))
}

Make Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
FROM golang:latest

# 将工作目录设置为 /app
WORKDIR /app

# 将当前目录下的所有内容复制到 /app 下
COPY . /app

# 允许宿主机访问容器的 8000 端口
EXPOSE 9000

# 设置容器进程为:go run helloworld.go
CMD go run helloworld.go

Build Image

1
docker build -t helloworld:1.0 .

Start container

1
docker run -d --name myhello -p 9000:9000 helloworld:1.0
This post is licensed under CC BY 4.0 by the author.